github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/process_registry_test.go (about) 1 package actor 2 3 import ( 4 "strconv" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestUint64ToId(t *testing.T) { 11 cases := []struct { 12 i uint64 13 e string 14 }{ 15 {0xfedcba9876543210, "$fXsKFxSl38g"}, 16 {0x0, "$0"}, 17 {0x1, "$1"}, 18 {0xf, "$f"}, 19 {0x1041041041041041, "$11111111111"}, 20 } 21 for _, tc := range cases { 22 t.Run(tc.e, func(t *testing.T) { 23 s := uint64ToId(tc.i) 24 assert.Equal(t, tc.e, s) 25 }) 26 } 27 } 28 29 var ss string 30 31 func BenchmarkUint64ToId(b *testing.B) { 32 var s string 33 for i := 0; i < b.N; i++ { 34 s = uint64ToId(uint64(i) << 5) 35 } 36 ss = s 37 } 38 39 func BenchmarkUint64ToString2(b *testing.B) { 40 var s string 41 var buf [12]byte 42 for i := 0; i < b.N; i++ { 43 s = string(strconv.AppendUint(buf[:], uint64(i)<<5, 36)) 44 } 45 ss = s 46 }