-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprocess-bench.py
executable file
·46 lines (35 loc) · 1.11 KB
/
process-bench.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
#!/usr/bin/env python3
import os
import subprocess
import sys
last_day = None
total_day_time = 0
days = []
new_env = os.environ.copy()
new_env['RUSTFLAGS'] = '-C target-cpu=native'
p = subprocess.Popen(['cargo', 'bench', '--bench', 'benchmark', '--', '--output-format=bencher', '2022'],
text=True,
stdout=subprocess.PIPE,
env=new_env)
for line in p.stdout:
line = line.strip()
if not line: continue
# test 2022_01_1 ... bench: 23235 ns/iter (+/- 92)
parts = [x for x in line.split(" ") if x]
day = int(parts[1][5:7])
time = int(parts[4]) / 1_000_000
print(f"Day {day}..", file=sys.stderr)
if day == last_day:
total_day_time += time
else:
if last_day:
days.append((last_day, total_day_time))
total_day_time = time
last_day = day
days.append((last_day, total_day_time))
total_time = sum(t for (d,t) in days)
for (d,t) in days:
percentage = (t / total_time) * 100
print(f"Day {d:>2}: {t:>5.2f} ms {percentage:>5.2f} %")
print("")
print(f"Total: {total_time:0.2f} ms")