Skip to content
Myr

plot_parametrized.py

This file

Path

scripts/plot_parametrized.py

48 lines · 1.2 KiB · Python

Last changed by

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

History of this file

Take it

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 1–11why, one step back
1#!/usr/bin/python
23"""This program shows parametrized `hyperfine` benchmark results as an4errorbar plot."""56import argparse7import json8import matplotlib.pyplot as plt910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results", nargs="+")

Auto-format Python scriptssharkdpbefore adoption8fff864

lines 12–17why, one step back
12parser.add_argument(
13 "--parameter-name",14 metavar="name",15 type=str,16 help="Name of the parameter / x-axis label",17)

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

lines 18–24why, one step back
18parser.add_argument(
19 "--log-x", help="Use a logarithmic x (parameter) axis", action="store_true"20)21parser.add_argument(22 "--log-time", help="Use a logarithmic time axis", action="store_true"23)24

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 25–34why, one step back
25args = parser.parse_args()
2627for filename in args.file:28 with open(filename) as f:29 results = json.load(f)["results"]3031 parameter_values = [float(b["parameter"]) for b in results]32 times_mean = [b["mean"] for b in results]33 times_stddev = [b["stddev"] for b in results]34

Auto-format Python scriptssharkdpbefore adoption8fff864

line 35why, one step back
35 plt.errorbar(x=parameter_values, y=times_mean, yerr=times_stddev, capsize=2)

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

lines 36–38why, one step back
36
37plt.xlabel(args.parameter_name)38plt.ylabel("Time [s]")

Add --log-time and --log-x flagssharkdpbefore adoptionc649d8d

lines 39–47why, one step back
39
40if args.log_time:41 plt.yscale("log")42else:43 plt.ylim(0, None)4445if args.log_x:46 plt.xscale("log")47

Add plot_parametrized.py scriptsharkdpbefore adoption0d22a96

line 48why, one step back
48plt.show()