Skip to content
Myr

plot_histogram.py

This file

Path

scripts/plot_histogram.py

27 lines · 724 bytes · Python

Last changed by

Add a script to plot histogramssharkdpbefore adoptionef8a166

History of this file

Take it

1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json7import matplotlib.pyplot as plt89parser = argparse.ArgumentParser(description=__doc__)10parser.add_argument("file", help="JSON file with benchmark results")11parser.add_argument("--title", help="Plot title")12args = parser.parse_args()1314with open(args.file) as f:15    results = json.load(f)["results"]1617commands = [b["command"] for b in results]18all_times = [b["times"] for b in results]1920plt.hist(all_times, label=commands, bins="auto", histtype="bar")21plt.legend(prop={'family': ['Source Code Pro', 'Fira Mono', 'Courier New']})2223plt.xlabel("Time [s]")24if args.title:25    plt.title(args.title)2627plt.show()