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
Provenance
- Commit
65dd84f- Tree
40a9f82- Author
David Peter <mail@david-peter.de>- Committer
David Peter <david.peter@bosch.com>- Parent
b0d29f0
5 files changed+49 added−46 removed
modified:scripts/advanced_statistics.py+9 added-12 removed
20 unmodified lines21 p95 = np.percentile(ts, 95)22 23 iqr = p75 - p2524 25- 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 lines5 import argparse6 import json7 import numpy as np8 import matplotlib.pyplot as plt9-import matplotlib.font_manager9 10 parser = argparse.ArgumentParser(description=__doc__)11 parser.add_argument("file", help="JSON file with benchmark results")12 parser.add_argument("--title", help="Plot title")1 unmodified line14 "--labels", help="Comma-separated list of entries for the plot legend"15 )16 parser.add_argument("--bins", help="Number of bins (default: auto)")17 parser.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+)36 parser.add_argument(37 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"38 )39 parser.add_argument("-o", "--output", help="Save image to the given filename.")34 unmodified lines74 histtype=histtype,75 range=(t_min, t_max),76 )77 plt.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+)83 84 plt.xlabel("Time [s]")85 if args.title:86 plt.title(args.title)10 unmodified linesmodified:scripts/plot_parametrized.py+5 added-10 removed
23 unmodified lines24 )25 parser.add_argument(26 "--titles", help="Comma-separated list of titles for the plot legend"27 )28-parser.add_argument(29- "-o", "--output", help="Save image to the given filename."30-)28+parser.add_argument("-o", "--output", help="Save image to the given filename.")29 30 args = parser.parse_args()31 if args.parameter_name is not None:32 sys.stderr.write(2 unmodified lines35 )36 37 38 def die(msg):41- sys.stderr.write("fatal: %s\n" % (msg,))39+ sys.stderr.write(f"fatal: {msg}\n")40 sys.exit(1)41 42 43 def extract_parameters(results):3 unmodified lines47 (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))54 55 3 unmodified lines59 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 lines74 75 (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_name81 82 times_mean = [b["mean"] for b in results]22 unmodified linesmodified:scripts/plot_whisker.py+5 added-7 removed
13 unmodified lines14 15 parser = argparse.ArgumentParser(description=__doc__)16 parser.add_argument("file", help="JSON file with benchmark results")17 parser.add_argument("--title", help="Plot Title")18-parser.add_argument("--sort-by", choices=['median'], help="Sort method")18+parser.add_argument("--sort-by", choices=["median"], help="Sort method")19 parser.add_argument(20 "--labels", help="Comma-separated list of entries for the plot legend"21 )22-parser.add_argument(23- "-o", "--output", help="Save image to the given filename."24-)22+parser.add_argument("-o", "--output", help="Save image to the given filename.")23 24 args = parser.parse_args()25 28-with open(args.file, encoding='utf-8') as f:26+with open(args.file, encoding="utf-8") as f:27 results = json.load(f)["results"]28 29 if args.labels:30 labels = args.labels.split(",")31 else:32 labels = [b["command"] for b in results]33 times = [b["times"] for b in results]34 37-if args.sort_by == 'median':35+if 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 lines50 plt.title(args.title)51 plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")52 plt.ylabel("Time [s]")53 plt.ylim(0, None)56-plt.xticks(list(range(1, len(labels)+1)), labels, rotation=45)54+plt.xticks(list(range(1, len(labels) + 1)), labels, rotation=45)55 if args.output:56 plt.savefig(args.output)57 else:58 plt.show()modified:scripts/welch_ttest.py+7 added-7 removed
18 unmodified lines19 if len(results) != 2:20 print("The input file has to contain exactly two benchmarks")21 sys.exit(1)22 23-a, b = [x["command"] for x in results[:2]]24-X, Y = [x["times"] for x in results[:2]]23+a, b = (x["command"] for x in results[:2])24+X, Y = (x["times"] for x in results[:2])25 26-print("Command 1: {}".format(a))27-print("Command 2: {}\n".format(b))26+print(f"Command 1: {a}")27+print(f"Command 2: {b}\n")28 29 t, p = stats.ttest_ind(X, Y, equal_var=False)30 th = 0.0531 dispose = p < th32-print("t = {:.3}, p = {:.3}".format(t, p))32+print(f"t = {t:.3}, p = {p:.3}")33 print()34 35 if 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}).")37 else:38- print("The two benchmarks are almost the same (p >= {}).".format(th))38+ print(f"The two benchmarks are almost the same (p >= {th}).")