Skip to content

Instantly share code, notes, and snippets.

@cdiener
Last active March 6, 2017 18:55
Show Gist options
  • Save cdiener/f326c33f331b370c6596fcf83d9d4bb4 to your computer and use it in GitHub Desktop.
Save cdiener/f326c33f331b370c6596fcf83d9d4bb4 to your computer and use it in GitHub Desktop.
Compare pytest benchmarks
import json
import pandas as pd
from sys import argv, exit
def benchmark_to_df(json_file):
with open(json_file) as jf:
content = json.load(jf)
df = pd.DataFrame(columns=("test", "time [ms]"))
for b in content["benchmarks"]:
df = df.append({"test": b["name"],
"time [ms]": b["stats"]["mean"]*1000.0},
ignore_index=True)
return df
if __name__ == "__main__":
if len(argv) != 3:
print("Usage: compare.py before.json after.json")
exit(1)
before = benchmark_to_df(argv[1])
after = benchmark_to_df(argv[2])
both = pd.merge(before, after, how="inner", on="test",
suffixes=(" before", " after"))
both["fraction"] = both.iloc[:, 1] / both.iloc[:, 2]
print(both.sort("fraction"))
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment