2018-02-24 07:57:25 -05:00
|
|
|
package dice_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
. "github.com/v2fly/v2ray-core/v5/common/dice"
|
2018-02-24 07:57:25 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkRoll1(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
Roll(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRoll20(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
Roll(20)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIntn1(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
rand.Intn(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIntn20(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
rand.Intn(20)
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 00:00:25 -05:00
|
|
|
|
2020-11-14 00:06:07 -05:00
|
|
|
func BenchmarkInt63(b *testing.B) {
|
2020-11-14 00:00:25 -05:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-11-14 00:06:07 -05:00
|
|
|
_ = uint16(rand.Int63() >> 47)
|
2020-11-14 00:00:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 00:06:07 -05:00
|
|
|
func BenchmarkInt31(b *testing.B) {
|
2020-11-14 00:00:25 -05:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-11-14 00:06:07 -05:00
|
|
|
_ = uint16(rand.Int31() >> 15)
|
2020-11-14 00:00:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIntn(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_ = uint16(rand.Intn(65536))
|
|
|
|
}
|
|
|
|
}
|