소스 검색

benchmark for dice

Darien Raymond 8 년 전
부모
커밋
2b4104e491
1개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 32 0
      common/dice/dice_test.go

+ 32 - 0
common/dice/dice_test.go

@@ -0,0 +1,32 @@
+package dice_test
+
+import (
+	"math/rand"
+	"testing"
+
+	. "v2ray.com/core/common/dice"
+)
+
+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)
+	}
+}