dice_test.go 738 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dice_test
  2. import (
  3. "math/rand"
  4. "testing"
  5. . "github.com/xtls/xray-core/common/dice"
  6. )
  7. func BenchmarkRoll1(b *testing.B) {
  8. for i := 0; i < b.N; i++ {
  9. Roll(1)
  10. }
  11. }
  12. func BenchmarkRoll20(b *testing.B) {
  13. for i := 0; i < b.N; i++ {
  14. Roll(20)
  15. }
  16. }
  17. func BenchmarkIntn1(b *testing.B) {
  18. for i := 0; i < b.N; i++ {
  19. rand.Intn(1)
  20. }
  21. }
  22. func BenchmarkIntn20(b *testing.B) {
  23. for i := 0; i < b.N; i++ {
  24. rand.Intn(20)
  25. }
  26. }
  27. func BenchmarkInt63(b *testing.B) {
  28. for i := 0; i < b.N; i++ {
  29. _ = uint16(rand.Int63() >> 47)
  30. }
  31. }
  32. func BenchmarkInt31(b *testing.B) {
  33. for i := 0; i < b.N; i++ {
  34. _ = uint16(rand.Int31() >> 15)
  35. }
  36. }
  37. func BenchmarkIntn(b *testing.B) {
  38. for i := 0; i < b.N; i++ {
  39. _ = uint16(rand.Intn(65536))
  40. }
  41. }