Skip to content

Commit 3466ca2

Browse files
committed
refactor(bench): formatting and linting
1 parent 78594af commit 3466ca2

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

scripts/compare_benchmarks.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import json
88
import sys
9-
from typing import Dict, List, Tuple
9+
from typing import Dict, Tuple
1010
from pathlib import Path
1111

1212

@@ -58,7 +58,7 @@ def calculate_change(baseline: float, current: float) -> Tuple[float, str]:
5858

5959
def load_benchmark_results(filepath: str) -> Dict:
6060
"""Load benchmark results from JSON file."""
61-
with open(filepath, 'r') as f:
61+
with open(filepath, "r") as f:
6262
return json.load(f)
6363

6464

@@ -69,26 +69,26 @@ def compare_benchmarks(baseline_path: str, current_path: str) -> str:
6969

7070
# Build lookup dictionaries for easier comparison
7171
baseline_results = {}
72-
for bench in baseline['benchmarks']:
73-
template_name = bench['template_name']
72+
for bench in baseline["benchmarks"]:
73+
template_name = bench["template_name"]
7474
# Get the largest input size result
75-
if bench['results']:
76-
baseline_results[template_name] = bench['results'][-1]
75+
if bench["results"]:
76+
baseline_results[template_name] = bench["results"][-1]
7777

7878
current_results = {}
79-
for bench in current['benchmarks']:
80-
template_name = bench['template_name']
81-
if bench['results']:
82-
current_results[template_name] = bench['results'][-1]
79+
for bench in current["benchmarks"]:
80+
template_name = bench["template_name"]
81+
if bench["results"]:
82+
current_results[template_name] = bench["results"][-1]
8383

8484
# Generate report
8585
report = []
8686
report.append("# 📊 Benchmark Comparison Report\n")
8787

8888
# Get input size from first template
8989
input_size = 0
90-
if current['benchmarks'] and current['benchmarks'][0]['results']:
91-
input_size = current['benchmarks'][0]['results'][-1]['input_size']
90+
if current["benchmarks"] and current["benchmarks"][0]["results"]:
91+
input_size = current["benchmarks"][0]["results"][-1]["input_size"]
9292

9393
report.append(f"**Input Size:** {input_size:,} paths\n")
9494
report.append(f"**Baseline Timestamp:** {baseline.get('timestamp', 'unknown')}")
@@ -101,33 +101,42 @@ def compare_benchmarks(baseline_path: str, current_path: str) -> str:
101101

102102
# Build comparison table
103103
report.append("## Performance Comparison\n")
104-
report.append("| Template | Avg/Path | Change | p95 | Change | Throughput | Change |")
105-
report.append("|----------|----------|--------|-----|--------|------------|--------|")
104+
report.append(
105+
"| Template | Avg/Path | Change | p95 | Change | Throughput | Change |"
106+
)
107+
report.append(
108+
"|----------|----------|--------|-----|--------|------------|--------|"
109+
)
106110

107111
# Sort by template name for consistent ordering
108112
all_templates = sorted(set(baseline_results.keys()) | set(current_results.keys()))
109113

110114
for template_name in all_templates:
111-
if template_name not in baseline_results or template_name not in current_results:
115+
if (
116+
template_name not in baseline_results
117+
or template_name not in current_results
118+
):
112119
continue # Skip if not in both sets
113120

114121
base = baseline_results[template_name]
115122
curr = current_results[template_name]
116123

117124
# Compare avg time per path
118-
base_avg_ns = base['avg_time_per_path']
119-
curr_avg_ns = curr['avg_time_per_path']
125+
base_avg_ns = base["avg_time_per_path"]
126+
curr_avg_ns = curr["avg_time_per_path"]
120127
avg_change, avg_emoji = calculate_change(base_avg_ns, curr_avg_ns)
121128

122129
# Compare p95
123-
base_p95 = base['latency_stats']['p95']
124-
curr_p95 = curr['latency_stats']['p95']
130+
base_p95 = base["latency_stats"]["p95"]
131+
curr_p95 = curr["latency_stats"]["p95"]
125132
p95_change, p95_emoji = calculate_change(base_p95, curr_p95)
126133

127134
# Compare throughput (higher is better, so invert the change)
128-
base_throughput = base['throughput_paths_per_sec']
129-
curr_throughput = curr['throughput_paths_per_sec']
130-
throughput_change = ((curr_throughput - base_throughput) / base_throughput) * 100
135+
base_throughput = base["throughput_paths_per_sec"]
136+
curr_throughput = curr["throughput_paths_per_sec"]
137+
throughput_change = (
138+
(curr_throughput - base_throughput) / base_throughput
139+
) * 100
131140
# Invert emoji logic for throughput
132141
if abs(throughput_change) < 2:
133142
throughput_emoji = "➖"
@@ -220,6 +229,7 @@ def main():
220229
except Exception as e:
221230
print(f"Error comparing benchmarks: {e}")
222231
import traceback
232+
223233
traceback.print_exc()
224234
sys.exit(1)
225235

0 commit comments

Comments
 (0)