Skip to content
Myr

plot_histogram.py

This file

Path

scripts/plot_histogram.py

37 lines · 879 bytes · Python

Last changed by

Fix computation of min/max time rangesharkdpbefore adoptiondab1da9

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

Fix computation of min/max time rangesharkdpbefore adoptiondab1da9

lines 21–23why, one step back
21t_min = np.min(list(map(np.min, all_times)))
22t_max = np.max(list(map(np.max, all_times)))23

Auto-format Python scriptssharkdpbefore adoption8fff864

lines 24–28why, one step back
24plt.hist(
25 all_times,26 label=commands,27 bins="auto",28 histtype="bar",

Fix computation of min/max time rangesharkdpbefore adoptiondab1da9

line 29why, one step back
29 range=(t_min, t_max),

Auto-format Python scriptssharkdpbefore adoption8fff864

lines 30–31why, one step back
30)
31plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})

Add a script to plot histogramssharkdpbefore adoptionef8a166

lines 32–37why, one step back
32
33plt.xlabel("Time [s]")34if args.title:35 plt.title(args.title)3637plt.show()