github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/internal/wyhash/wyhash_test.go (about) 1 package wyhash 2 3 import ( 4 "fmt" 5 "runtime" 6 "testing" 7 ) 8 9 func BenchmarkWyhash(b *testing.B) { 10 sizes := []int{17, 21, 24, 29, 32, 11 33, 64, 69, 96, 97, 128, 129, 240, 241, 12 512, 1024, 100 * 1024, 13 } 14 15 for size := 0; size <= 16; size++ { 16 b.Run(fmt.Sprintf("%d", size), func(b *testing.B) { 17 b.SetBytes(int64(size)) 18 var ( 19 x uint64 20 data = string(make([]byte, size)) 21 ) 22 b.ReportAllocs() 23 b.ResetTimer() 24 25 for i := 0; i < b.N; i++ { 26 x = Sum64String(data) 27 } 28 runtime.KeepAlive(x) 29 }) 30 } 31 32 for _, size := range sizes { 33 b.Run(fmt.Sprintf("%d", size), func(b *testing.B) { 34 b.SetBytes(int64(size)) 35 var x uint64 36 data := string(make([]byte, size)) 37 b.ReportAllocs() 38 b.ResetTimer() 39 40 for i := 0; i < b.N; i++ { 41 x = Sum64String(data) 42 } 43 runtime.KeepAlive(x) 44 }) 45 } 46 }