Created
March 23, 2017 15:39
-
-
Save bbengfort/e048b647ae8c94dc1d6465342d7ba34d to your computer and use it in GitHub Desktop.
Runner for benchmarking grumpy fibonnacci
This file contains 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 csv | |
import time | |
import subprocess | |
import progressbar | |
from copy import copy | |
from dateutil.relativedelta import relativedelta | |
CMDS = { | |
"fib.go": ["./fib",], | |
"fibpy.go": ["./fibpy",], | |
"fib.py": ["python", "fib.py"], | |
} | |
def runcmd(cmd, arg): | |
start = time.time() | |
cmd = copy(CMDS[cmd]) | |
cmd.append(str(arg)) | |
subprocess.run(cmd, stdout=subprocess.PIPE) | |
return time.time() - start | |
def runall(samples=20, cmds=["fib.go", "fibpy.go", "fib.py"], args=[25,30,35,40]): | |
nruns = samples * len(cmds) * len(args) | |
count = 0 | |
with progressbar.ProgressBar(max_value=nruns, redirect_stdout=True) as bar: | |
with open('times.csv', 'w') as f: | |
writer = csv.writer(f) | |
writer.writerow(["cmd", "arg", "time"]) | |
for _ in range(samples): | |
for arg in args: | |
for cmd in cmds: | |
delta = runcmd(cmd, arg) | |
count += 1 | |
writer.writerow([cmd, arg, delta]) | |
f.flush() | |
bar.update(count) | |
if __name__ == '__main__': | |
runall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment