forked from cardrank/cardrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
96 lines (90 loc) · 2.01 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cardrank
import (
"fmt"
"reflect"
"runtime"
"testing"
)
func BenchmarkRanker(b *testing.B) {
for _, r := range rankers(true) {
for i, ff := range []func(*testing.B, RankerFunc, int){
bench5, bench6, bench7,
} {
ranker, f := r, ff
rankerName := runtime.FuncForPC(reflect.ValueOf(ranker).Pointer()).Name()
b.Run(fmt.Sprintf("%s/%d", rankerName, i+5), func(b *testing.B) {
f(b, ranker, b.N)
})
}
}
}
func bench5(b *testing.B, f RankerFunc, n int) {
count := 0
for c0 := 0; c0 < 52; c0++ {
for c1 := c0 + 1; c1 < 52; c1++ {
for c2 := c1 + 1; c2 < 52; c2++ {
for c3 := c2 + 1; c3 < 52; c3++ {
for c4 := c3 + 1; c4 < 52; c4++ {
r = f([]Card{allCards[c0], allCards[c1], allCards[c2], allCards[c3], allCards[c4]})
if r > HighCard {
b.Fail()
}
count++
if n <= count {
return
}
}
}
}
}
}
}
func bench6(b *testing.B, f RankerFunc, n int) {
count := 0
for c0 := 0; c0 < 52; c0++ {
for c1 := c0 + 1; c1 < 52; c1++ {
for c2 := c1 + 1; c2 < 52; c2++ {
for c3 := c2 + 1; c3 < 52; c3++ {
for c4 := c3 + 1; c4 < 52; c4++ {
for c5 := c4 + 1; c5 < 52; c5++ {
r = f([]Card{allCards[c0], allCards[c1], allCards[c2], allCards[c3], allCards[c4], allCards[c5]})
if r > HighCard {
b.Fail()
}
count++
if n <= count {
return
}
}
}
}
}
}
}
}
func bench7(b *testing.B, f RankerFunc, n int) {
count := 0
for c0 := 0; c0 < 52; c0++ {
for c1 := c0 + 1; c1 < 52; c1++ {
for c2 := c1 + 1; c2 < 52; c2++ {
for c3 := c2 + 1; c3 < 52; c3++ {
for c4 := c3 + 1; c4 < 52; c4++ {
for c5 := c4 + 1; c5 < 52; c5++ {
for c6 := c5 + 1; c6 < 52; c6++ {
r = f([]Card{allCards[c0], allCards[c1], allCards[c2], allCards[c3], allCards[c4], allCards[c5], allCards[c6]})
if r > HighCard {
b.Fail()
}
count++
if n <= count {
return
}
}
}
}
}
}
}
}
}
var r HandRank