github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/utils/hash/murmurhash_test.go (about) 1 package hash 2 3 import ( 4 "fmt" 5 "github.com/nyan233/littlerpc/core/utils/random" 6 "math/rand" 7 "strconv" 8 "testing" 9 "time" 10 ) 11 12 func TestMurmurHash(t *testing.T) { 13 for i := 0; i < 100; i++ { 14 _ = Murmurhash3Onx8632([]byte(strconv.FormatInt(rand.Int63(), 10)), 16) 15 } 16 } 17 18 func BenchmarkMurmurHash(b *testing.B) { 19 b.ReportAllocs() 20 for i := 32; i < 2048; i *= 2 { 21 seed := time.Now().Unix() 22 b.Run(fmt.Sprintf("Murmurhash-%d", i), func(b *testing.B) { 23 randStr := genBytes(i) 24 b.ResetTimer() 25 for i := 0; i < b.N; i++ { 26 _ = Murmurhash3Onx8632(randStr, uint32(seed)) 27 } 28 }) 29 } 30 } 31 32 func genBytes(n int) []byte { 33 bytes := make([]byte, n) 34 for i := 0; i < n; i++ { 35 bytes[i] = byte(random.FastRandN(26)) + 65 36 } 37 return bytes 38 }