-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* < 50% allocations BenchmarkUint64ToId-8 50000000 30.6 ns/op 7 B/op 1 allocs/op BenchmarkUint64ToString2-8 20000000 125 ns/op 63 B/op 2 allocs/op
- Loading branch information
1 parent
bb76b0b
commit 2ca7813
Showing
2 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package actor | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUint64ToId(t *testing.T) { | ||
cases := []struct { | ||
i uint64 | ||
e string | ||
}{ | ||
{0xfedcba9876543210, "$fXsKFxSl38g"}, | ||
{0x0, "$0"}, | ||
{0x1, "$1"}, | ||
{0xf, "$f"}, | ||
{0x1041041041041041, "$11111111111"}, | ||
} | ||
for _, tc := range cases { | ||
t.Run(tc.e, func(t *testing.T) { | ||
s := uint64ToId(tc.i) | ||
assert.Equal(t, tc.e, s) | ||
}) | ||
} | ||
|
||
} | ||
|
||
var ss string | ||
|
||
func BenchmarkUint64ToId(b *testing.B) { | ||
var s string | ||
for i := 0; i < b.N; i++ { | ||
s = uint64ToId(uint64(i)<<5) | ||
} | ||
ss = s | ||
} | ||
|
||
func BenchmarkUint64ToString2(b *testing.B) { | ||
var s string | ||
var buf [12]byte | ||
for i := 0; i < b.N; i++ { | ||
s = string(strconv.AppendUint(buf[:], uint64(i)<<5, 36)) | ||
} | ||
ss = s | ||
} |