in scripts/generate-comparison.py [0:0]
def generate_query_speedup_chart(baseline, comparison, label1: str, label2: str, benchmark: str, title: str):
results = []
for query in range(1, query_count(benchmark)+1):
a = np.median(np.array(baseline[str(query)]))
b = np.median(np.array(comparison[str(query)]))
if a > b:
speedup = a/b-1
else:
speedup = -(1/(a/b)-1)
results.append(("q" + str(query), round(speedup*100, 0)))
results = sorted(results, key=lambda x: -x[1])
queries, speedups = zip(*results)
# Create figure and axis
if benchmark == "tpch":
fig, ax = plt.subplots(figsize=(10, 6))
else:
fig, ax = plt.subplots(figsize=(35, 10))
# Create bar chart
bars = ax.bar(queries, speedups, color='skyblue')
# Add text annotations
for bar, speedup in zip(bars, speedups):
yval = bar.get_height()
if yval >= 0:
ax.text(bar.get_x() + bar.get_width() / 2.0, min(800, yval+5), f'{yval:.0f}%', va='bottom', ha='center', fontsize=8,
color='blue', rotation=90)
else:
ax.text(bar.get_x() + bar.get_width() / 2.0, yval, f'{yval:.0f}%', va='top', ha='center', fontsize=8,
color='blue', rotation=90)
# Add title and labels
ax.set_title(label2 + " speedup over " + label1 + " (" + title + ")")
ax.set_ylabel('Speedup (100% speedup = 2x faster)')
ax.set_xlabel('Query')
# Customize the y-axis to handle both positive and negative values better
ax.axhline(0, color='black', linewidth=0.8)
min_value = (min(speedups) // 100) * 100
max_value = ((max(speedups) // 100) + 1) * 100 + 50
if benchmark == "tpch":
ax.set_ylim(min_value, max_value)
else:
# TODO improve this
ax.set_ylim(-250, 300)
# Show grid for better readability
ax.yaxis.grid(True)
# Save the plot as an image file
plt.savefig(f'{benchmark}_queries_speedup.png', format='png')