-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbench.py
executable file
·37 lines (28 loc) · 1.16 KB
/
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
#!/usr/bin/env python3
r"""Small tool to produce input data for https://github.com/nico/ministat
(which was originally at https://github.com/thorduri/ministat)
Example:
bench.py -o before.txt out/gn/bin/ld64.lld.darwinnew @response.txt
# ...rebuild lld with some change...
bench.py -o after.txt out/gn/bin/ld64.lld.darwinnew @response.txt
ministat before.txt after.txt
"""
import argparse, subprocess, sys, time
parser = argparse.ArgumentParser(
epilog=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-n', help='number of repetitions', default=5, type=int)
parser.add_argument('--output', '-o', help='write timing output to this file')
parser.add_argument('cmd', nargs=argparse.REMAINDER, help='command to time')
args = parser.parse_args()
if args.cmd and args.cmd[0] == '--': # Make `bench.py -o foo -- cmd` work
del args.cmd[0]
if not args.cmd:
parser.print_usage()
sys.exit(1)
out = open(args.output, 'w') if args.output else sys.stdout
subprocess.call(args.cmd) # Warmup
for _ in range(args.n):
t = time.time();
subprocess.call(args.cmd)
print(time.time() - t, file=out)