Skip to content
Myr

Update formatting, use f-strings

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent b0d29f0 · Browse files · 5 files+49 added−46 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+49 added−46 removed

  • other:+49 added−46 removed

5 files+49 added−46 removed

modified:scripts/advanced_statistics.py+9 added-12 removed
20 unmodified lines
21 p95 = np.percentile(ts, 95)2223 iqr = p75 - p252425 print("Command '{}'".format(command))26 print(" runs: {:8d}".format(len(ts)))27 print(" mean: {:8.3f} s".format(np.mean(ts)))28 print(" stddev: {:8.3f} s".format(np.std(ts, ddof=1)))29 print(" median: {:8.3f} s".format(np.median(ts)))30 print(" min: {:8.3f} s".format(np.min(ts)))31 print(" max: {:8.3f} s".format(np.max(ts)))25 print(f"Command '{command}'")26 print(f" runs: {len(ts):8d}")27 print(f" mean: {np.mean(ts):8.3f} s")28 print(f" stddev: {np.std(ts, ddof=1):8.3f} s")29 print(f" median: {np.median(ts):8.3f} s")30 print(f" min: {np.min(ts):8.3f} s")31 print(f" max: {np.max(ts):8.3f} s")32 print()33 print(" percentiles:")34 print(" P_05 .. P_95: {:.3f} s .. {:.3f} s".format(p05, p95))35 print(36 " P_25 .. P_75: {:.3f} s .. {:.3f} s "37 "(IQR = {:.3f} s)".format(p25, p75, iqr)38 )34 print(f" P_05 .. P_95: {p05:.3f} s .. {p95:.3f} s")35 print(f" P_25 .. P_75: {p25:.3f} s .. {p75:.3f} s " f"(IQR = {iqr:.3f} s)")36 print()
modified:scripts/plot_histogram.py+23 added-10 removed
4 unmodified lines
5import argparse6import json7import numpy as np8import matplotlib.pyplot as plt9import matplotlib.font_manager910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results")12parser.add_argument("--title", help="Plot title")
1 unmodified line
14 "--labels", help="Comma-separated list of entries for the plot legend"15)16parser.add_argument("--bins", help="Number of bins (default: auto)")17parser.add_argument(19 "--legend-location", help="Location of the legend on plot (default: upper center)",20 choices=["upper center", "lower center", "right", "left", "best", "upper left", "upper right", "lower left", "lower right", "center left", "center right", "center"],21 default="upper center"22 )18 "--legend-location",19 help="Location of the legend on plot (default: upper center)",20 choices=[21 "upper center",22 "lower center",23 "right",24 "left",25 "best",26 "upper left",27 "upper right",28 "lower left",29 "lower right",30 "center left",31 "center right",32 "center",33 ],34 default="upper center",35)36parser.add_argument(37 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"38)39parser.add_argument("-o", "--output", help="Save image to the given filename.")
34 unmodified lines
74 histtype=histtype,75 range=(t_min, t_max),76)77plt.legend(65 loc=args.legend_location,66 fancybox=True,67 shadow=True,68 prop={"size": 7, "family": ["Source Code Pro", "Fira Mono", "Courier New"]}69 )78 loc=args.legend_location,79 fancybox=True,80 shadow=True,81 prop={"size": 10, "family": ["Source Code Pro", "Fira Mono", "Courier New"]},82)8384plt.xlabel("Time [s]")85if args.title:86 plt.title(args.title)
10 unmodified lines
modified:scripts/plot_parametrized.py+5 added-10 removed
23 unmodified lines
24)25parser.add_argument(26 "--titles", help="Comma-separated list of titles for the plot legend"27)28parser.add_argument(29 "-o", "--output", help="Save image to the given filename."30)28parser.add_argument("-o", "--output", help="Save image to the given filename.")2930args = parser.parse_args()31if args.parameter_name is not None:32 sys.stderr.write(
2 unmodified lines
35 )363738def die(msg):41 sys.stderr.write("fatal: %s\n" % (msg,))39 sys.stderr.write(f"fatal: {msg}\n")40 sys.exit(1)414243def extract_parameters(results):
3 unmodified lines
47 (names, values) = zip(*(unique_parameter(b) for b in results))48 names = frozenset(names)49 if len(names) != 1:50 die(53 "benchmarks must all have the same parameter name, but found: %s"54 % sorted(names)51 f"benchmarks must all have the same parameter name, but found: {sorted(names)}"52 )53 return (next(iter(names)), list(values))5455
3 unmodified lines
59 if not params_dict:60 die("benchmarks must have exactly one parameter, but found none")61 if len(params_dict) > 1:62 die(66 "benchmarks must have exactly one parameter, but found multiple: %s"67 % sorted(params_dict)63 f"benchmarks must have exactly one parameter, but found multiple: {sorted(params_dict)}"64 )65 [(name, value)] = params_dict.items()66 return (name, float(value))67
6 unmodified lines
7475 (this_parameter_name, parameter_values) = extract_parameters(results)76 if parameter_name is not None and this_parameter_name != parameter_name:77 die(82 "files must all have the same parameter name, but found %r vs. %r"83 % (parameter_name, this_parameter_name)78 f"files must all have the same parameter name, but found {parameter_name!r} vs. {this_parameter_name!r}"79 )80 parameter_name = this_parameter_name8182 times_mean = [b["mean"] for b in results]
22 unmodified lines
modified:scripts/plot_whisker.py+5 added-7 removed
13 unmodified lines
1415parser = argparse.ArgumentParser(description=__doc__)16parser.add_argument("file", help="JSON file with benchmark results")17parser.add_argument("--title", help="Plot Title")18parser.add_argument("--sort-by", choices=['median'], help="Sort method")18parser.add_argument("--sort-by", choices=["median"], help="Sort method")19parser.add_argument(20 "--labels", help="Comma-separated list of entries for the plot legend"21)22parser.add_argument(23 "-o", "--output", help="Save image to the given filename."24)22parser.add_argument("-o", "--output", help="Save image to the given filename.")2324args = parser.parse_args()2528with open(args.file, encoding='utf-8') as f:26with open(args.file, encoding="utf-8") as f:27 results = json.load(f)["results"]2829if args.labels:30 labels = args.labels.split(",")31else:32 labels = [b["command"] for b in results]33times = [b["times"] for b in results]3437if args.sort_by == 'median':35if args.sort_by == "median":36 medians = [b["median"] for b in results]37 indices = sorted(range(len(labels)), key=lambda k: medians[k])38 labels = [labels[i] for i in indices]39 times = [times[i] for i in indices]
10 unmodified lines
50 plt.title(args.title)51plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")52plt.ylabel("Time [s]")53plt.ylim(0, None)56plt.xticks(list(range(1, len(labels)+1)), labels, rotation=45)54plt.xticks(list(range(1, len(labels) + 1)), labels, rotation=45)55if args.output:56 plt.savefig(args.output)57else:58 plt.show()
modified:scripts/welch_ttest.py+7 added-7 removed
18 unmodified lines
19if len(results) != 2:20 print("The input file has to contain exactly two benchmarks")21 sys.exit(1)2223a, b = [x["command"] for x in results[:2]]24X, Y = [x["times"] for x in results[:2]]23a, b = (x["command"] for x in results[:2])24X, Y = (x["times"] for x in results[:2])2526print("Command 1: {}".format(a))27print("Command 2: {}\n".format(b))26print(f"Command 1: {a}")27print(f"Command 2: {b}\n")2829t, p = stats.ttest_ind(X, Y, equal_var=False)30th = 0.0531dispose = p < th32print("t = {:.3}, p = {:.3}".format(t, p))32print(f"t = {t:.3}, p = {p:.3}")33print()3435if dispose:36 print("There is a difference between the two benchmarks (p < {}).".format(th))36 print(f"There is a difference between the two benchmarks (p < {th}).")37else:38 print("The two benchmarks are almost the same (p >= {}).".format(th))38 print(f"The two benchmarks are almost the same (p >= {th}).")