plot_histogram.py
This file
Path
scripts/plot_histogram.py
34 lines · 812 bytes · Python
Last changed by
Auto-format Python scriptssharkdpbefore adoption8fff864
History of this fileTake it
Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 1–6why, one step back1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import jsonShow the full range in histogramsDavid Peterbefore adoptiona3f0278
line 7why, one step back7import numpy as npAdd a script to plot histogramssharkdpbefore adoptionef8a166
lines 8–20why, one step back8import matplotlib.pyplot as plt910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results")12parser.add_argument("--title", help="Plot title")13args = parser.parse_args()1415with open(args.file) as f:16 results = json.load(f)["results"]1718commands = [b["command"] for b in results]19all_times = [b["times"] for b in results]20Auto-format Python scriptssharkdpbefore adoption8fff864
lines 21–28why, one step back21plt.hist(22 all_times,23 label=commands,24 bins="auto",25 histtype="bar",26 range=(np.min(all_times), np.max(all_times)),27)28plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 29–34why, one step back2930plt.xlabel("Time [s]")31if args.title:32 plt.title(args.title)3334plt.show()