Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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",],
"": ["python", ""],
def runcmd(cmd, arg):
start = time.time()
cmd = copy(CMDS[cmd])
cmd.append(str(arg)), stdout=subprocess.PIPE)
return time.time() - start
def runall(samples=20, cmds=["fib.go", "fibpy.go", ""], 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])
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment