1# To run this script run the command 'python3 scripts/generate_plots_flow_flatten_merge.py' in the /benchmarks folder 2 3 4import pandas as pd 5import sys 6import locale 7import matplotlib.pyplot as plt 8from matplotlib.ticker import FormatStrFormatter 9 10input_file = "build/reports/jmh/results.csv" 11output_file = "out/flow-flatten-merge.svg" 12# Please change the value of this variable according to the FlowFlattenMergeBenchmarkKt.ELEMENTS 13elements = 100000 14benchmark_name = "benchmarks.flow.FlowFlattenMergeBenchmark.flattenMerge" 15csv_columns = ["Benchmark", "Score", "Unit", "Param: concurrency", "Param: flowsNumberStrategy"] 16rename_columns = {"Benchmark": "benchmark", "Score" : "score", "Unit" : "unit", 17 "Param: concurrency" : "concurrency", "Param: flowsNumberStrategy" : "flows"} 18 19markers = ['.', 'v', '^', '1', '2', '8', 'p', 'P', 'x', 'D', 'd', 's'] 20colours = ['red', 'gold', 'sienna', 'olivedrab', 'lightseagreen', 'navy', 'blue', 'm', 'crimson', 'yellow', 'orangered', 'slateblue', 'aqua', 'black', 'silver'] 21 22def next_colour(): 23 i = 0 24 while True: 25 yield colours[i % len(colours)] 26 i += 1 27 28def next_marker(): 29 i = 0 30 while True: 31 yield markers[i % len(markers)] 32 i += 1 33 34def 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 55langlocale = locale.getdefaultlocale()[0] 56locale.setlocale(locale.LC_ALL, langlocale) 57dp = locale.localeconv()['decimal_point'] 58if dp == ",": 59 csv_columns.append("Score Error (99,9%)") 60 rename_columns["Score Error (99,9%)"] = "score_error" 61elif dp == ".": 62 csv_columns.append("Score Error (99.9%)") 63 rename_columns["Score Error (99.9%)"] = "score_error" 64else: 65 print("Unexpected locale delimeter: " + dp) 66 sys.exit(1) 67data = pd.read_csv(input_file, sep=",", decimal=dp) 68data = data[csv_columns].rename(columns=rename_columns) 69data = data[(data.benchmark == benchmark_name)] 70plt.rcParams.update({'font.size': 15}) 71plt.figure(figsize=(12.5, 10)) 72draw(data, plt) 73plt.legend(loc='upper center', borderpad=0, bbox_to_anchor=(0.5, 1.3), ncol=2, frameon=False, borderaxespad=2, prop={'size': 15}) 74plt.tight_layout(pad=12, w_pad=2, h_pad=1) 75plt.savefig(output_file, bbox_inches='tight') 76