Modernize running benchmarks and reporting errors

This commit is contained in:
andrew authored and Andrew Grant committed 2024-02-02 05:35:19 -05:00
1 parent 8f250c2c3f
commit c268b47e4d
7 files changed
+175 -170

No files matched your search

+12 -73
View File
@@ -21,87 +21,26 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import argparse
import multiprocessing
import re
import subprocess
import os
import sys
def parse_stream_output(stream):
# Needed to include from ../Client/*.py
PARENT = os.path.join(os.path.dirname(__file__), os.path.pardir)
sys.path.append(os.path.abspath(PARENT))
nps = bench = None # Search through output Stream
for line in stream.decode('ascii').strip().split('\n')[::-1]:
# Convert non alpha-numerics to spaces
line = re.sub(r'[^a-zA-Z0-9 ]+', ' ', line)
# Multiple methods, including Ethereal and Stockfish
nps_pattern = r'(\d+\s+nps)|(nps\s+\d+)|(nodes second\s+\d+)'
bench_pattern = r'(\d+\s+nodes)|(nodes\s+\d+)|(nodes searched\s+\d+)'
# Search for and set only once the NPS value
if (re_nps := re.search(nps_pattern, line, re.IGNORECASE)):
nps = nps if nps else re_nps.group()
# Search for and set only once the Bench value
if (re_bench := re.search(bench_pattern, line, re.IGNORECASE)):
bench = bench if bench else re_bench.group()
# Parse out the integer portion from our matches
nps = int(re.search(r'\d+', nps ).group()) if nps else None
bench = int(re.search(r'\d+', bench).group()) if bench else None
return (bench, nps)
def single_core_bench(engine, network, outqueue):
# Basic command for Public engines
cmd = ['./' + engine, 'bench']
# Adjust to handle setting Networks in Private engines
if network:
option = 'setoption name EvalFile value %s' % (network)
cmd = ['./%s' % (engine), option, 'bench', 'quit']
# Launch the bench and wait for results
stdout, stderr = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
).communicate()
outqueue.put(parse_stream_output(stdout))
def multi_core_bench(engine, network, threads):
outqueue = multiprocessing.Queue()
processes = [
multiprocessing.Process(
target=single_core_bench,
args=(engine, network, outqueue)
) for ii in range(threads)
]
for process in processes: process.start()
return [outqueue.get() for ii in range(threads)]
def run_benchmark(engine, network, threads, sets):
benches, speeds = [], []
for ii in range(sets):
for bench, speed in multi_core_bench(engine, network, threads):
benches.append(bench); speeds.append(speed)
if len(set(benches)) != 1:
print("Error: Non-Deterministic Results!")
return (0, 0)
return int(sum(speeds) / len(speeds)), benches[0]
from Client.bench import run_benchmark
if __name__ == '__main__':
p = argparse.ArgumentParser()
p.add_argument('-E', '--engine' , help='Binary Name', required=True)
p.add_argument('-N', '--network' , help='Networks for Private Engines', required=False)
p.add_argument('-T', '--threads' , help='Concurrent Benchmarks', required=True)
p.add_argument('-S', '--sets' , help='Benchmark Sample Count', required=True)
p.add_argument('-T', '--threads' , help='Concurrent Benchmarks', required=True, type=int)
p.add_argument('-S', '--sets' , help='Benchmark Sample Count', required=True, type=int)
args = p.parse_args()
print (run_benchmark(args.engine, args.network, int(args.threads), int(args.sets)))
private = args.network != None
speed, bench = run_benchmark(args.engine, args.network, private, args.threads, args.sets)
print('Bench for %s is %d' % (args.engine, bench))
print('Speed for %s is %d' % (args.engine, speed))