-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_test.go
60 lines (54 loc) · 1.17 KB
/
random_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package random_test
import (
"github.com/azeroth-sha/random"
"testing"
)
// func TestUint64(t *testing.T) {
// // random.DisableRandPool()
// random.EnableRandPool()
// for i := 0; i < 256; i++ {
// var count int64
// for j := 0; j < 100000; j++ {
// // random.DisableRandPool()
// // fmt.Printf("----%d---- %d\r\n", i, random.Uint64())
// // random.EnableRandPool()
// // fmt.Printf("----%d---- %d\r\n", i, random.Uint64())
// if random.Uint8() == uint8(i) {
// count++
// }
// }
// log.Printf("num: %d; count: %d\r\n", i, count)
// }
// }
func BenchmarkInt32(b *testing.B) {
random.DisableRandPool()
b.ResetTimer()
for i := 0; i < b.N; i++ {
random.Int32()
}
}
func BenchmarkInt32WithPool(b *testing.B) {
random.EnableRandPool()
b.ResetTimer()
for i := 0; i < b.N; i++ {
random.Int32()
}
}
func BenchmarkInt32WithParallel(b *testing.B) {
random.DisableRandPool()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
random.Int32()
}
})
}
func BenchmarkInt32WithPoolAndParallel(b *testing.B) {
random.EnableRandPool()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
random.Int32()
}
})
}