-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
115 lines (95 loc) · 4.23 KB
/
graph.py
File metadata and controls
115 lines (95 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import csv
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
file_map = {
'clang_linux_benchmark_analysis.csv': 'Clang (Linux)',
'g++_linux_benchmark_analysis.csv': 'G++ (Linux)',
'mingw_win_benchmark_analysis.csv': 'MinGW (Win, per-call)',
'msvc_win_benchmark_analysis.csv': 'MSVC (Win, per-call)',
'time_mingw_win_benchmark_analysis.csv': 'MinGW (Win, batch)',
'time_msvc_win_benchmark_analysis.csv': 'MSVC (Win, batch)'
}
metrics = ['Average_ns', 'Median_ns', 'P95_ns', 'P99_ns']
all_results = []
for filename, source_name in file_map.items():
if not os.path.exists(filename):
continue
try:
with open(filename, mode='r', encoding='utf-8') as f:
reader = csv.DictReader(f)
source_data = list(reader)
baseline = None
for row in source_data:
version = row['Version'].strip('_')
if version == 'Original':
baseline = float(row['Average_ns'])
break
if baseline is None:
continue
for row in source_data:
version = row['Version'].strip('_')
avg_ns = float(row['Average_ns'])
median_ns = float(row['Median_ns'])
p95_ns = float(row['P95_ns'])
p99_ns = float(row['P99_ns'])
speedup = baseline / avg_ns if avg_ns > 0 else 0
all_results.append({
'Source': source_name,
'Version': version,
'Average_ns': avg_ns,
'Median_ns': median_ns,
'P95_ns': p95_ns,
'P99_ns': p99_ns,
'Speedup': speedup
})
except Exception as e:
print(f"Error processing {filename}: {e}")
if not all_results:
print("No results to process.")
exit()
df = pd.DataFrame(all_results)
df.to_csv('performance_comparison_detailed.csv', index=False)
# Main Summary Plot (Average & Speedup)
sns.set_theme(style="whitegrid", context="talk")
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(14, 12))
sns.barplot(data=df, x='Source', y='Average_ns', hue='Version', ax=ax1)
ax1.set_title('Average Execution Time (ns) - Lower is Better')
ax1.set_ylabel('Time (ns)')
ax1.set_xlabel('')
ax1.tick_params(axis='x', rotation=15)
ax1.legend(title='Version', bbox_to_anchor=(1.05, 1), loc='upper left')
sns.barplot(data=df, x='Source', y='Speedup', hue='Version', ax=ax2)
ax2.set_title('Speedup vs Original (Average) - Higher is Better')
ax2.set_ylabel('Speedup (x)')
ax2.set_xlabel('Compiler / Platform')
ax2.tick_params(axis='x', rotation=15)
ax2.axhline(1, ls='--', color='red', alpha=0.5)
ax2.legend(title='Version', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.savefig('benchmark_summary_charts.png')
# Detailed Plot (Tail Latencies)
fig_det, (ax3, ax4) = plt.subplots(2, 1, figsize=(14, 12))
df_melted_tail = df.melt(id_vars=['Source', 'Version'], value_vars=['P95_ns', 'P99_ns'], var_name='Metric', value_name='Time_ns')
sns.barplot(data=df_melted_tail, x='Source', y='Time_ns', hue='Version', ax=ax3)
ax3.set_title('Tail Latency (P95 & P99) - Lower is Better')
ax3.set_ylabel('Time (ns)')
ax3.set_xlabel('')
ax3.tick_params(axis='x', rotation=15)
ax3.legend(title='Version', bbox_to_anchor=(1.05, 1), loc='upper left')
# Speedup Heatmap (Version vs Source)
pivot_speedup = df.pivot(index='Version', columns='Source', values='Speedup')
sns.heatmap(pivot_speedup, annot=True, fmt=".2f", cmap="YlGnBu", ax=ax4)
ax4.set_title('Speedup Relative to Original (Heatmap)')
plt.tight_layout()
plt.savefig('benchmark_summary_charts_detailed.png')
print("\n=== SUMMARY ANALYSIS ===")
for source in df['Source'].unique():
source_df = df[df['Source'] == source]
best_row = source_df.loc[source_df['Speedup'].idxmax()]
print(f"{source:<25}: Best is {best_row['Version']} ({best_row['Speedup']:.2f}x speedup)")
print("\nCharts updated:")
print("- benchmark_summary_charts.png: Average Time and Speedup")
print("- benchmark_summary_charts_detailed.png: Tail Latencies and Speedup Heatmap")
print("- performance_comparison_detailed.csv: Raw data table")