-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmbench
More file actions
executable file
·45 lines (40 loc) · 1.58 KB
/
mmbench
File metadata and controls
executable file
·45 lines (40 loc) · 1.58 KB
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 python
import argparse
import ast
import subprocess
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('group', type=str, help='which benchmark to run')
parser.add_argument('-b', '--bench', type=str, default='', help='Which specific benchmark to run')
parser.add_argument('-n', type=str, default='auto', help='Run how many times (default: auto)')
args = parser.parse_args()
GROUP = args.group
BENCH = args.bench
N = [] if args.n == 'auto' else ['-n', args.n]
# discover
if GROUP.startswith('benchmarks/run_'):
GROUP = GROUP[15:-3]
if BENCH != '':
benches = [BENCH]
else:
benches = sorted(
list(
map(
lambda x: x[4:],
filter(
lambda x: x.startswith('run'),
ast.literal_eval(
subprocess.run(['python', '-c', f'from benchmarks import run_{GROUP}; print(dir(run_{GROUP}))'],
capture_output=True,
check=True).stdout.decode('utf-8'))))))
WIDTH = max(map(lambda x: len(x), benches))
for b in benches:
# check
subprocess.run(['python', '-c', f'from benchmarks import run_{GROUP}; run_{GROUP}.check(run_{GROUP}.run_{b}())'],
check=True)
# bench
t = subprocess.run(
['python', '-m', 'timeit', *N, '-s', f'from benchmarks import run_{GROUP}', f'run_{GROUP}.run_{b}()'],
capture_output=True,
check=True).stdout.decode('utf-8').strip()
# display
print('#', GROUP, b, ' ' * (WIDTH - len(b)), t)