Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created March 23, 2017 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/e048b647ae8c94dc1d6465342d7ba34d to your computer and use it in GitHub Desktop.
Save bbengfort/e048b647ae8c94dc1d6465342d7ba34d to your computer and use it in GitHub Desktop.
Runner for benchmarking grumpy fibonnacci
#!/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