11
11
from pathlib import Path
12
12
from subprocess import check_output
13
13
14
+ _results_file = 'benchmark-results.txt'
15
+
16
+
14
17
def _record_measurement (bench : str , time : int ) -> None :
15
18
print ('{}: {}ms' .format (bench , time ), flush = True )
16
- with open ('benchmark-results.txt' , 'at' ) as f :
17
- f .write ('{},{}' .format (bench , time ))
19
+ with open (_results_file , 'at' ) as f :
20
+ f .write ('{},{}\n ' .format (bench , time ))
18
21
19
- def run_connection_pool_bench (
22
+
23
+ def _run_connection_pool (
20
24
exe_dir : Path ,
21
25
iters : int ,
22
26
server_host : str ,
@@ -39,7 +43,7 @@ def run_connection_pool_bench(
39
43
_record_measurement (bench , time )
40
44
41
45
42
- def run_protocol_bench (
46
+ def _run_protocol (
43
47
exe_dir : Path ,
44
48
iters : int ,
45
49
) -> None :
@@ -62,3 +66,17 @@ def run_protocol_bench(
62
66
time = int (check_output ([exe ]).decode ())
63
67
_record_measurement (bench , time )
64
68
69
+
70
+ def run_benchmarks (
71
+ exe_dir : Path ,
72
+ server_host : str ,
73
+ connection_pool_iters : int ,
74
+ protocol_iters : int ,
75
+ ) -> None :
76
+ # Truncate the results file, if it exists
77
+ with open (_results_file , 'wt' ) as f :
78
+ pass
79
+
80
+ # Run the benchmarks
81
+ _run_connection_pool (exe_dir , connection_pool_iters , server_host )
82
+ _run_protocol (exe_dir , protocol_iters )
0 commit comments