This repository was archived by the owner on Dec 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.cc
More file actions
100 lines (79 loc) · 2.5 KB
/
benchmark.cc
File metadata and controls
100 lines (79 loc) · 2.5 KB
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
97
98
99
100
#include <benchmark/benchmark.h>
#include "strategy.h"
#include <random>
namespace
{
constexpr Sint16 operator ""_si16(unsigned long long __value) noexcept
{ return static_cast<Sint16>(__value); }
Sint16 random()
{
std::random_device device;
std::mt19937 generator(device());
std::bernoulli_distribution is_empty(.8);
std::bernoulli_distribution player;
return
is_empty(generator) ? -1_si16 :
static_cast<Sint16>(player(generator));
}
class BM_Strategy : public benchmark::Fixture
{
public:
void SetUp(benchmark::State& __state) override
{
bidiarray<bool> holes;
for (std::size_t i = 0; i != 8; ++i) {
for (std::size_t j = 0; j != 8; ++j) {
bool is_hole = (i % 2) == (j % 2);
blobs.set(i, j, is_hole ? -1 : random());
holes.set(i, j, is_hole);
}
}
strategy = Strategy(blobs, holes, 0, [] (movement&) {});
}
public:
bidiarray<Sint16> blobs;
Strategy strategy;
};
BENCHMARK_DEFINE_F(BM_Strategy, BM_min_max_seq)(benchmark::State& __state)
{
strategy._max_level = static_cast<Uint16>(__state.range(0));
for (auto _ : __state) {
strategy.min_max_seq(blobs, 1, 0);
}
__state.SetComplexityN(__state.range(0));
}
BENCHMARK_DEFINE_F(BM_Strategy, BM_min_max_para)(benchmark::State& __state)
{
strategy._max_level = static_cast<Uint16>(__state.range(0));
for (auto _ : __state) {
strategy.min_max_para(blobs, 1, 0);
}
__state.SetComplexityN(__state.range(0));
}
BENCHMARK_DEFINE_F(BM_Strategy, BM_alpha_beta_seq)(
benchmark::State& __state
)
{
strategy._max_level = static_cast<Uint16>(__state.range(0));
for (auto _ : __state) {
strategy.alpha_beta_seq(
blobs,
1,
0,
-std::numeric_limits<Sint32>::max(),
std::numeric_limits<Sint32>::max()
);
}
__state.SetComplexityN(__state.range(0));
}
}
BENCHMARK_REGISTER_F(BM_Strategy, BM_min_max_seq)
->DenseRange(1, 6)
->Complexity();
BENCHMARK_REGISTER_F(BM_Strategy, BM_min_max_para)
->DenseRange(1, 6)
->Complexity();
BENCHMARK_REGISTER_F(BM_Strategy, BM_alpha_beta_seq)
->DenseRange(1, 6)
->Complexity();
BENCHMARK_MAIN();