Created
June 13, 2025 08:07
-
-
Save AndyGrant/cd716ddde784f17013f64e4d72d57494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import argparse | |
| import os | |
| import subprocess | |
| from multiprocessing import Pool | |
| CMD_SEQUENCE = [ | |
| 'setoption name Minimal value true', | |
| 'bench movetime 1000', | |
| 'quit' | |
| ] | |
| def run_engine(enumerated_args): | |
| index, args = enumerated_args | |
| binary = args.engine | |
| if args.copies: | |
| binary += str(1 + index % args.copies) | |
| proc = subprocess.Popen( | |
| [binary], | |
| stdin=subprocess.PIPE, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.STDOUT, | |
| text=True, | |
| bufsize=1 | |
| ) | |
| for cmd in CMD_SEQUENCE: | |
| proc.stdin.write(cmd + '\n') | |
| proc.stdin.flush() | |
| # Expecting: XXXX nodes YYYY nps | |
| return int(proc.stdout.readlines()[-1].strip().split()[2]) | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--start', type=int, default=1, help='Concurrency starting point') | |
| parser.add_argument('--end', type=int, default=os.cpu_count(), help='Concurrency ending point') | |
| parser.add_argument('--step', type=int, default=1, help='Jump by N threads at a time') | |
| parser.add_argument('--engine', type=str, required=True, help='Path to the engine executable') | |
| parser.add_argument('--copies', type=int, default=0, help='Open N "different" binaries to simulate containers') | |
| args = parser.parse_args() | |
| for threads in range(args.start, args.end+1, args.step): | |
| task_args = [(i, args) for i in range(threads)] | |
| with Pool(processes=threads) as pool: | |
| results = pool.map(run_engine, task_args) | |
| print (','.join([str(f) for f in results])) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment