mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
rand
This commit is contained in:
42
rand/rand_generator_test.go
Normal file
42
rand/rand_generator_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package rand
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFastGenerate(t *testing.T) {
|
||||
g := NewFastRandGenerator()
|
||||
for i := 0; i < 100; i++ {
|
||||
t.Log(g.Int63())
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGenerate(b *testing.B) {
|
||||
b.Run("fast", func(b *testing.B) {
|
||||
g1 := NewFastRandGenerator()
|
||||
for i := 0; i < b.N; i++ {
|
||||
g1.Int31()
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("normal", func(b *testing.B) {
|
||||
g1 := NewRandGenerator()
|
||||
for i := 0; i < b.N; i++ {
|
||||
g1.Int31()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkParallel(b *testing.B) {
|
||||
g1 := NewFastRandGenerator()
|
||||
b.RunParallel(func(p *testing.PB) {
|
||||
for p.Next() {
|
||||
g1.Int31()
|
||||
}
|
||||
})
|
||||
|
||||
g2 := NewRandGenerator()
|
||||
b.RunParallel(func(p *testing.PB) {
|
||||
for p.Next() {
|
||||
g2.Int()
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user