-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.rs
114 lines (99 loc) · 4.87 KB
/
bench.rs
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Bench is primarily used for testing the engine to verify that a change
//! does not introduce functional issues and that the engine's behavior
//! remains consistent. This is considered assuming that the change is not
//! activated by very rare conditions or only activated at a higher depth
//! than specified.
//!
//! Note that although it can be used as a benchmarking tool,
//! it is not comprehensive enough to be definitive.
use std::time::Instant;
use crate::{
board::Board,
search::{self, Options},
tables::{CorrectionHistory, History, TranspositionTable},
time::Limits,
};
const POSITIONS: &[&str] = &[
"2k5/2P3p1/3r1p2/7p/2RB2rP/3K2P1/5P2/8 w - - 1 48",
"8/8/1k1NK3/r7/2R2P1P/3n2P1/8/8 b - - 0 59",
"r1r3k1/1bqnbp1N/ppn1p1p1/4P1B1/8/2N5/PPB1QPPP/R3R1K1 w - - 3 9",
"2kr1b1r/pp1qpp2/1np4p/3n1Pp1/3PN2B/2N2Q2/1PP3PP/2KRR3 w - g6 0 12",
"r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1",
"6k1/8/pB2p1p1/3p3p/7q/PB6/Q7/2R3K1 w - - 0 37",
"8/8/1p2k2P/1P6/P3B3/4B1K1/1b3P2/4n3 w - - 7 77",
"7r/p1r1p2p/2k5/1p2n1N1/1Pp5/2R1P1P1/P4P1P/3R1K2 w - - 2 31",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"5rk1/1p2r1p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3p2B1/3P2b1/4PN2/q3BPPP/1R1QK2R b Kk - 1 4",
"1r4k1/1q3bp1/6r1/pp1pPpB1/2p1nP2/P1P1QB1P/1P4RK/R7 w - - 1 38",
"r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10",
"r2q1rk1/1bpnbppp/1p2p3/8/p2PN3/2P2N2/PP1Q1PPP/1B1RR1K1 b - - 1 14",
"r4rk1/2qbbppp/p1n1p3/8/2p2P2/P1N1BNQ1/1PP3PP/3R1RK1 b - - 5 11",
"r4rk1/1bq1ppbp/6p1/2p5/P3P3/4BP2/1P1QN1PP/R2R2K1 w - - 2 11",
"8/5pk1/4pr2/8/3Q1P2/7K/8/8 b - - 76 136",
"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1",
"8/1k4p1/p4p1p/n1B5/2P3P1/7P/4KP2/8 w - - 0 41",
"8/2q2p1k/1p2p1p1/4P1P1/p7/P4Q2/1p3PK1/1R6 b - - 3 38",
"2r5/1pqn1pbk/p2p1np1/P2Pp1Bp/NPr1P3/6PP/3Q1PB1/1RR3K1 b - - 6 12",
"6k1/5pbp/R5p1/Pp6/8/1r2P2P/6B1/6K1 w - - 0 31",
"1r2qrk1/2p1bpp1/3p4/1pP2b1p/1P2N1nP/4P1P1/1BQ2PB1/3R2KR w - - 3 22",
"2q1r1k1/1p2npbp/p5p1/8/8/2P2N1P/P2B1PP1/2QR2K1 w - - 2 17",
"rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8",
"8/8/1k1r2p1/p1p2nPp/P3RN1P/8/4KP2/8 b - - 13 55",
"5r1k/1p3p1p/2p2p2/1q2bP1Q/3p1P2/1PP1R1P1/6KP/2N5 w - - 0 25",
"8/8/5pk1/5Nn1/R3r1P1/8/6K1/8 w - - 4 65",
];
/// Runs a fixed depth search on the bench positions.
pub fn bench<const PRETTY: bool>(depth: i32) {
if PRETTY {
println!("{}", "-".repeat(50));
println!("{:>15} {:>13} {:>15}", "Nodes", "Elapsed", "NPS");
println!("{}", "-".repeat(50));
}
let time = Instant::now();
let mut nodes = 0;
let mut index = 0;
for position in POSITIONS {
let now = Instant::now();
let options = Options { threads: 1, silent: true, limits: Limits::FixedDepth(depth) };
let mut board = Board::new(position).unwrap();
let mut history = History::default();
let mut corrhist = CorrectionHistory::default();
let tt = TranspositionTable::default();
let result = search::start(options, &mut board, &mut history, &mut corrhist, &tt);
nodes += result.nodes;
index += 1;
let seconds = now.elapsed().as_secs_f64();
let knps = result.nodes as f64 / seconds / 1000.0;
if PRETTY {
println!("{index:>3} {:>11} {seconds:>12.3}s {knps:>15.3} kN/s", result.nodes);
}
}
let seconds = time.elapsed().as_secs_f64();
let knps = nodes as f64 / seconds / 1000.0;
if PRETTY {
println!("{}", "-".repeat(50));
println!("{nodes:>15} {seconds:>12.3}s {knps:>15.3} kN/s");
println!("{}", "-".repeat(50));
} else {
let nps = nodes as f64 / seconds;
println!("Bench: {nodes} nodes {nps:.0} nps");
}
}