|
| 1 | +# To run this script run the command 'python3 scripts/generate_plots_flow_flatten_merge.py' in the /benchmarks folder |
| 2 | + |
| 3 | + |
| 4 | +import pandas as pd |
| 5 | +import sys |
| 6 | +import locale |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +from matplotlib.ticker import FormatStrFormatter |
| 9 | + |
| 10 | +input_file = "build/reports/jmh/results.csv" |
| 11 | +output_file = "out/flow-flatten-merge.svg" |
| 12 | +# Please change the value of this variable according to the FlowFlattenMergeBenchmarkKt.ELEMENTS |
| 13 | +elements = 100000 |
| 14 | +benchmark_name = "benchmarks.flow.FlowFlattenMergeBenchmark.flattenMerge" |
| 15 | +csv_columns = ["Benchmark", "Score", "Unit", "Param: concurrency", "Param: flowsNumberStrategy"] |
| 16 | +rename_columns = {"Benchmark": "benchmark", "Score" : "score", "Unit" : "unit", |
| 17 | + "Param: concurrency" : "concurrency", "Param: flowsNumberStrategy" : "flows"} |
| 18 | + |
| 19 | +markers = ['.', 'v', '^', '1', '2', '8', 'p', 'P', 'x', 'D', 'd', 's'] |
| 20 | +colours = ['red', 'gold', 'sienna', 'olivedrab', 'lightseagreen', 'navy', 'blue', 'm', 'crimson', 'yellow', 'orangered', 'slateblue', 'aqua', 'black', 'silver'] |
| 21 | + |
| 22 | +def next_colour(): |
| 23 | + i = 0 |
| 24 | + while True: |
| 25 | + yield colours[i % len(colours)] |
| 26 | + i += 1 |
| 27 | + |
| 28 | +def next_marker(): |
| 29 | + i = 0 |
| 30 | + while True: |
| 31 | + yield markers[i % len(markers)] |
| 32 | + i += 1 |
| 33 | + |
| 34 | +def draw(data, plt): |
| 35 | + plt.xscale('log', basex=2) |
| 36 | + plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%0.f')) |
| 37 | + plt.grid(linewidth='0.5', color='lightgray') |
| 38 | + if data.unit.unique()[0] != "ops/s": |
| 39 | + print("Unexpected time unit: " + data.unit.unique()[0]) |
| 40 | + sys.exit(1) |
| 41 | + plt.ylabel("elements / ms") |
| 42 | + plt.xlabel('concurrency') |
| 43 | + plt.xticks(data.concurrency.unique()) |
| 44 | + |
| 45 | + colour_gen = next_colour() |
| 46 | + marker_gen = next_marker() |
| 47 | + for flows in data.flows.unique(): |
| 48 | + gen_colour = next(colour_gen) |
| 49 | + gen_marker = next(marker_gen) |
| 50 | + res = data[(data.flows == flows)] |
| 51 | +# plt.plot(res.concurrency, res.score*elements/1000, label="flows={}".format(flows), color=gen_colour, marker=gen_marker) |
| 52 | + plt.errorbar(x=res.concurrency, y=res.score*elements/1000, yerr=res.score_error*elements/1000, solid_capstyle='projecting', |
| 53 | + label="flows={}".format(flows), capsize=4, color=gen_colour, linewidth=2.2) |
| 54 | + |
| 55 | +langlocale = locale.getdefaultlocale()[0] |
| 56 | +locale.setlocale(locale.LC_ALL, langlocale) |
| 57 | +dp = locale.localeconv()['decimal_point'] |
| 58 | +if dp == ",": |
| 59 | + csv_columns.append("Score Error (99,9%)") |
| 60 | + rename_columns["Score Error (99,9%)"] = "score_error" |
| 61 | +elif dp == ".": |
| 62 | + csv_columns.append("Score Error (99.9%)") |
| 63 | + rename_columns["Score Error (99.9%)"] = "score_error" |
| 64 | +else: |
| 65 | + print("Unexpected locale delimeter: " + dp) |
| 66 | + sys.exit(1) |
| 67 | +data = pd.read_csv(input_file, sep=",", decimal=dp) |
| 68 | +data = data[csv_columns].rename(columns=rename_columns) |
| 69 | +data = data[(data.benchmark == benchmark_name)] |
| 70 | +plt.rcParams.update({'font.size': 15}) |
| 71 | +plt.figure(figsize=(12.5, 10)) |
| 72 | +draw(data, plt) |
| 73 | +plt.legend(loc='upper center', borderpad=0, bbox_to_anchor=(0.5, 1.3), ncol=2, frameon=False, borderaxespad=2, prop={'size': 15}) |
| 74 | +plt.tight_layout(pad=12, w_pad=2, h_pad=1) |
| 75 | +plt.savefig(output_file, bbox_inches='tight') |
0 commit comments