diff --git a/z/rtutil_test.go b/z/rtutil_test.go index e0f47084..4c15aff9 100644 --- a/z/rtutil_test.go +++ b/z/rtutil_test.go @@ -13,9 +13,24 @@ import ( func BenchmarkMemHash(b *testing.B) { buf := make([]byte, 64) rand.Read(buf) + + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = MemHash(buf) + } + b.SetBytes(int64(len(buf))) +} + +func BenchmarkMemHashString(b *testing.B) { + s := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." + + b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { - MemHash(buf) + _ = MemHashString(s) } + b.SetBytes(int64(len(s))) } func BenchmarkSip(b *testing.B) { diff --git a/z/z.go b/z/z.go index a9c06b37..8b284ce2 100644 --- a/z/z.go +++ b/z/z.go @@ -36,8 +36,7 @@ func KeyToHash(key interface{}) (uint64, uint64) { case uint64: return k, 0 case string: - raw := []byte(k) - return MemHash(raw), xxhash.Sum64(raw) + return MemHashString(k), xxhash.Sum64String(k) case []byte: return MemHash(k), xxhash.Sum64(k) case byte: