github.com/imannamdari/v2ray-core/v5@v5.0.5/common/dice/dice_test.go (about)

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