Skip to content
Myr

plot_histogram.py

This file

Path

scripts/plot_histogram.py

32 lines · 825 bytes · Python

Last changed by

Show the full range in histogramsDavid Peterbefore adoptiona3f0278

History of this file

Take it

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 1–6why, one step back
1#!/usr/bin/python
23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json

Show the full range in histogramsDavid Peterbefore adoptiona3f0278

line 7why, one step back
7import numpy as np

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 8–20why, one step back
8import matplotlib.pyplot as plt
910parser = 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]20

Show the full range in histogramsDavid Peterbefore adoptiona3f0278

lines 21–25why, one step back
21plt.hist(all_times,
22 label=commands,23 bins="auto",24 histtype="bar",25 range=(np.min(all_times), np.max(all_times)))

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 26–32why, one step back
26plt.legend(prop={'family': ['Source Code Pro', 'Fira Mono', 'Courier New']})
2728plt.xlabel("Time [s]")29if args.title:30 plt.title(args.title)3132plt.show()