1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-06-07 10:56:52 +08:00
parent 2728dcafeb
commit f36b4fabd6
7 changed files with 315 additions and 100 deletions

View 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()
}
})
}