github.com/chaowen112/go-lib@v0.0.0-20231018124935-124cd26d7cbe/randutils/uint32_test.go (about) 1 package randutils 2 3 import ( 4 "math/rand" 5 "testing" 6 "time" 7 ) 8 9 func BenchmarkRandUint32Std(b *testing.B) { 10 rand.Seed(time.Now().Unix()) 11 b.SetParallelism(1000) 12 b.ReportAllocs() 13 b.ResetTimer() 14 b.RunParallel(func(pb *testing.PB) { 15 for pb.Next() { 16 rand.Intn(100) 17 } 18 }) 19 } 20 21 func BenchmarkRandUint32(b *testing.B) { 22 b.SetParallelism(1000) 23 b.ReportAllocs() 24 b.ResetTimer() 25 b.RunParallel(func(pb *testing.PB) { 26 for pb.Next() { 27 Uint32n(100) 28 } 29 }) 30 }