plot_whisker.py
This file
Path
scripts/plot_whisker.py
41 lines · 1.3 KiB · Python
Last changed by
Add --labels option for plot_whisker.pysharkdpbefore adoptiona870d4d
History of this fileTake it
Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 1–16why, one step back1#!/usr/bin/python23"""This program shows `hyperfine` benchmark results as a box and whisker plot.45Quoting from the matplotlib documentation:6 The box extends from the lower to upper quartile values of the data, with7 a line at the median. The whiskers extend from the box to show the range8 of the data. Flier points are those past the end of the whiskers.9"""1011import argparse12import json13import matplotlib.pyplot as plt1415parser = argparse.ArgumentParser(description=__doc__)16parser.add_argument("file", help="JSON file with benchmark results")Update plot_whisker.pyEugene Obrezkovbefore adoptione83e1f7
line 17why, one step back17parser.add_argument("--title", help="Plot Title")Add --labels option for plot_whisker.pysharkdpbefore adoptiona870d4d
line 18why, one step back18parser.add_argument("--labels", help="Comma-separated list of entries for the plot legend")Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 19–23why, one step back19args = parser.parse_args()2021with open(args.file) as f:22 results = json.load(f)["results"]23Add --labels option for plot_whisker.pysharkdpbefore adoptiona870d4d
lines 24–27why, one step back24if args.labels:25 labels = args.labels.split(",")26else:27 labels = [b["command"] for b in results]Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 28–29why, one step back28times = [b["times"] for b in results]29Update plot_whisker.pyEugene Obrezkovbefore adoptione83e1f7
lines 30–37why, one step back30boxplot = plt.boxplot(times, vert=True, patch_artist=True)31cmap = plt.cm.get_cmap("rainbow")32colors = [cmap(val / len(times)) for val in range(len(times))]3334for patch, color in zip(boxplot["boxes"], colors):35 patch.set_facecolor(color)3637plt.title(args.title)Add --labels option for plot_whisker.pysharkdpbefore adoptiona870d4d
line 38why, one step back38plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")Add a script to plot histogramssharkdpbefore adoptionef8a166
line 39why, one step back39plt.ylabel("Time [s]")Update plot_whisker.pyEugene Obrezkovbefore adoption9253e9f
line 40why, one step back40plt.ylim(0, None)Add a script to plot histogramssharkdpbefore adoptionef8a166
line 41why, one step back41plt.show()