[update patch]
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by William Chargin · committed by David Peter · parent e75747a · Browse files · 2 files·+54 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- wchargin-branch: param-list-matrix
- wchargin-source: 188f18839ad4bfce20c2c031cd6b00bcd94b67ad
Diff stats
2 files+54 added−4 removed
- other:+54 added−4 removed
Provenance
- Commit
a8a75a3- Tree
557e6d1- Author
William Chargin <wchargin@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
e75747a
2 files changed+54 added−4 removed
modified:scripts/plot_parametrized.py+52 added-3 removed
4 unmodified lines5 6 import argparse7 import json8 import matplotlib.pyplot as plt9+import sys10 11 parser = argparse.ArgumentParser(description=__doc__)12 parser.add_argument("file", help="JSON file with benchmark results", nargs="+")13 parser.add_argument(14 "--parameter-name",15 metavar="name",16 type=str,16- help="Name of the parameter / x-axis label",17+ help="Deprecated; parameter names are now inferred from benchmark files",18 )19 parser.add_argument(20 "--log-x", help="Use a logarithmic x (parameter) axis", action="store_true"21 )4 unmodified lines26 "--titles", help="Comma-separated list of titles for the plot legend"27 )28 29 args = parser.parse_args()30+if args.parameter_name is not None:31+ sys.stderr.write(32+ "warning: --parameter-name is deprecated; names are inferred from "33+ "benchmark results\n"34+ )35 36+37+def die(msg):38+ sys.stderr.write("fatal: %s\n" % (msg,))39+ sys.exit(1)40+41+42+def extract_parameters(results):43+ """Return `(parameter_name: str, parameter_values: List[float])`."""44+ if not results:45+ die("no benchmark data to plot")46+ (names, values) = zip(*(unique_parameter(b) for b in results))47+ names = frozenset(names)48+ if len(names) != 1:49+ die(50+ "benchmarks must all have the same parameter name, but found: %s"51+ % sorted(names)52+ )53+ return (next(iter(names)), values)54+55+56+def unique_parameter(benchmark):57+ """Return the unique parameter `(name: str, value: float)`, or dies."""58+ params_dict = benchmark.get("parameters", {})59+ if not params_dict:60+ die("benchmarks must have exactly one parameter, but found none")61+ if len(params_dict) > 1:62+ die(63+ "benchmarks must have exactly one parameter, but found multiple: %s"64+ % sorted(params_dict)65+ )66+ return next(iter(params_dict.items()))67+68+69+parameter_name = None70+71 for filename in args.file:72 with open(filename) as f:73 results = json.load(f)["results"]74 34- parameter_values = [float(b["parameter"]) for b in results]75+ (this_parameter_name, parameter_values) = extract_parameters(results)76+ if parameter_name is not None and this_parameter_name != parameter_name:77+ die(78+ "files must all have the same parameter name, but found %r vs. %r"79+ % (parameter_name, this_parameter_name)80+ )81+ parameter_name = this_parameter_name82+83+ parameter_values = [float(pv) for pv in parameter_values]84 times_mean = [b["mean"] for b in results]85 times_stddev = [b["stddev"] for b in results]86 87 plt.errorbar(x=parameter_values, y=times_mean, yerr=times_stddev, capsize=2)88 40-plt.xlabel(args.parameter_name)89+plt.xlabel(parameter_name)90 plt.ylabel("Time [s]")91 92 if args.log_time:93 plt.yscale("log")10 unmodified linesmodified:CHANGELOG.md+2 added-1 removed
14 unmodified lines15 See: #253, #318 (@wchargin)16 17 ## Changes18 19-- When parameters are used with `--parameter-list` or `--parameter-scan`, the JSON export format now contains a dictionary `parameters` instead of a single key `parameter`.19+- When parameters are used with `--parameter-list` or `--parameter-scan`, the JSON export format now contains a dictionary `parameters` instead of a single key `parameter`. See #253, #318.20+- The `plot_parametrized.py` script now infers the parameter name, and its `--parameter-name` argument has been deprecated. See #253, #318.21 22 ## Bugfixes23 ## Other24 ## Packaging208 unmodified lines