-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchNormToolSF.py
76 lines (57 loc) · 1.76 KB
/
benchNormToolSF.py
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
import subprocess
import multiprocessing
import os
import sys
import time
IS_WINDOWS = os.name == 'nt'
def run_single_bench_sf(engine, queue):
bench_sig = None
bench_nps = None
p = subprocess.Popen(
[engine, "bench"],
stderr=subprocess.PIPE,
stdout=subprocess.DEVNULL,
universal_newlines=True,
bufsize=1,
close_fds=not IS_WINDOWS,
)
for line in iter(p.stderr.readline, ""):
if "Nodes searched" in line:
bench_sig = line.split(": ")[1].strip()
if "Nodes/second" in line:
bench_nps = float(line.split(": ")[1].strip())
queue.put((bench_sig, bench_nps))
def verify_signature(engine, active_cores):
queue = multiprocessing.Queue()
processes = [
multiprocessing.Process(
target=run_single_bench_sf,
args=(engine, queue),
) for _ in range(active_cores)
]
for p in processes:
p.start()
results = [queue.get() for _ in range(active_cores)]
bench_nps = 0.0
for sig, nps in results:
bench_nps += nps
bench_nps /= active_cores
return bench_nps
def main():
print("Running benchmark. This will take a minute")
if len(sys.argv) != 3:
print("Usage: python script.py <engine_path> <active_cores>")
sys.exit(1)
engine_path = sys.argv[1]
active_cores = int(sys.argv[2])
start_time = time.time()
total_nps = 0.0
count = 0
while time.time() - start_time < 60: # 5 minutes = 300 seconds
bench_nps = verify_signature(engine_path, active_cores)
total_nps += bench_nps
count += 1
average_nps = total_nps / count
print(f"Final Average Benchmark NPS over a minute: {average_nps}")
if __name__ == "__main__":
main()