chore: add benchmark analysis scripts

This commit is contained in:
2026-03-18 18:12:33 +00:00
parent e9ef5ebbcd
commit 5704942950
5 changed files with 195 additions and 1900 deletions
+70
View File
@@ -0,0 +1,70 @@
import csv
import sys
def analyze(filename, label):
durations = []
lengths = []
nodes = []
failed = 0
total = 0
stutters = 0
try:
with open(filename, 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if not row or row[0].startswith('#'):
if 'total_paths' in ','.join(row) if row else '':
continue
continue
total += 1
try:
d = int(row[1])
durations.append(d)
lengths.append(int(row[2]))
nodes.append(int(row[3]))
if d > 1000: stutters += 1
except:
pass
if not durations:
return
durations.sort()
lengths.sort()
nodes.sort()
p50 = durations[len(durations)//2]
p90 = durations[int(len(durations)*0.90)]
p99 = durations[int(len(durations)*0.99)]
max_d = durations[-1]
avg_nodes = sum(nodes) / len(nodes) if nodes else 0
avg_len = sum(lengths) / len(lengths) if lengths else 0
print(f"\n=== {label} ===")
print(f"Total paths: {total}")
print(f"P50: {p50}µs | P90: {p90}µs | P99: {p99}µs | Max: {max_d}µs")
print(f"Stutters (>1ms): {stutters} ({100*stutters/total:.2f}%)")
print(f"Avg nodes: {avg_nodes:.1f} | Avg length: {avg_len:.1f}")
print(f"Median length: {lengths[len(lengths)//2]}")
return durations, lengths, nodes, stutters, total
except Exception as e:
print(f"Error reading {filename}: {e}")
return None
base = analyze("/home/popertots/bench/pathfinding_benchmark_baseline_release.csv", "ORIGINAL BASELINE (>6 months ago, 5x5 map)")
cur = analyze("pathfinding_benchmark_current.csv", "CURRENT (15x15 map, after all fixes)")
if base and cur:
print("\n=== COMPARISON ===")
b_dur, b_len, b_nodes, b_stut, b_tot = base
c_dur, c_len, c_nodes, c_stut, c_tot = cur
p50_imp = (b_dur[len(b_dur)//2] - c_dur[len(c_dur)//2]) / b_dur[len(b_dur)//2] * 100
p99_imp = (b_dur[int(len(b_dur)*0.99)] - c_dur[int(len(c_dur)*0.99)]) / b_dur[int(len(b_dur)*0.99)] * 100
stutter_imp = (b_stut - c_stut) / b_stut * 100 if b_stut > 0 else 0
print(f"P50 improvement: {p50_imp:+.1f}%")
print(f"P99 improvement: {p99_imp:+.1f}%")
print(f"Stutter reduction: {stutter_imp:+.1f}%")
print(f"Map size: 5x5 -> 15x15 (9x larger area)")
+47
View File
@@ -0,0 +1,47 @@
import csv
def check_lengths(filename, label):
lengths = []
failed = 0
total = 0
with open(filename, 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if not row or row[0].startswith('#'):
continue
total += 1
try:
length = int(row[2])
lengths.append(length)
if length == 0:
failed += 1
except:
pass
print(f"\n=== {label} ===")
print(f"Total paths: {total}")
print(f"Failed paths (length=0): {failed} ({100*failed/total if total else 0:.1f}%)")
print(f"Paths with length > 0: {total - failed}")
if lengths:
avg = sum(lengths) / len(lengths)
print(f"Avg length (all): {avg:.1f}")
nonzero = [l for l in lengths if l > 0]
if nonzero:
print(f"Avg length (non-zero): {sum(nonzero)/len(nonzero):.1f}")
print(f"Max length: {max(lengths)}")
# Length buckets
print("\nLength distribution:")
buckets = [(0, 0), (1, 5), (6, 10), (11, 50), (51, 100), (100, 1000)]
for lo, hi in buckets:
if lo == hi == 0:
count = sum(1 for l in lengths if l == 0)
else:
count = sum(1 for l in lengths if lo <= l <= hi)
pct = 100*count/len(lengths) if lengths else 0
print(f" {lo}-{hi if hi < 1000 else 'inf'} nodes: {count} ({pct:.1f}%)")
check_lengths("/home/popertots/bench/pathfinding_benchmark_baseline_release.csv", "BASELINE")
check_lengths("pathfinding_benchmark_current.csv", "CURRENT")
+36
View File
@@ -0,0 +1,36 @@
import csv
def check_nodes(filename, label):
nodes_list = []
durations = []
with open(filename, 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if not row or row[0].startswith('#'):
continue
try:
nodes_list.append(int(row[3]))
durations.append(int(row[1]))
except:
pass
print(f"\n=== {label} NODES EXPANDED ===")
print(f"Total paths: {len(nodes_list)}")
# Group by node count
node_buckets = [(0, 0), (1, 64), (65, 200), (201, 500), (501, 1000), (1001, 10000)]
for lo, hi in node_buckets:
count = sum(1 for n in nodes_list if lo <= n <= hi)
pct = 100*count/len(nodes_list) if nodes_list else 0
print(f" {lo}-{hi if hi < 10000 else 'inf'} nodes: {count} ({pct:.1f}%)")
# Show duration correlation with nodes
print("\nDuration by node count:")
for lo, hi in [(1, 64), (65, 200), (201, 500), (501, 1000), (1001, 10000)]:
subset_durations = [d for n, d in zip(nodes_list, durations) if lo <= n <= hi]
if subset_durations:
avg = sum(subset_durations) / len(subset_durations)
print(f" {lo}-{hi if hi < 10000 else 'inf'} nodes: avg {avg:.0f}µs, count {len(subset_durations)}")
check_nodes("pathfinding_benchmark_current.csv", "CURRENT")
+42
View File
@@ -0,0 +1,42 @@
import csv
def analyze_tail(filename):
durations = []
with open(filename, 'r') as f:
reader = csv.reader(f)
next(reader)
for row in reader:
if not row or row[0].startswith('#'):
continue
try:
durations.append(int(row[1]))
except:
pass
durations.sort()
n = len(durations)
print(f"\n=== TAIL ANALYSIS ({filename}) ===")
print(f"Total: {n}")
print(f"P50: {durations[n//2]}µs")
print(f"P90: {durations[int(n*0.90)]}µs")
print(f"P95: {durations[int(n*0.95)]}µs")
print(f"P99: {durations[int(n*0.99)]}µs")
print(f"P99.5: {durations[int(n*0.995)]}µs")
print(f"P99.9: {durations[int(n*0.999)]}µs")
print(f"Max: {durations[-1]}µs")
# Count stutters
for threshold in [500, 1000, 2000, 3000, 5000]:
count = sum(1 for d in durations if d > threshold)
print(f"Paths > {threshold}µs: {count} ({100*count/n:.2f}%)")
# Distribution buckets
print("\n=== DISTRIBUTION ===")
buckets = [(0, 50), (50, 100), (100, 200), (200, 500), (500, 1000), (1000, 2000), (2000, 5000), (5000, float('inf'))]
for lo, hi in buckets:
count = sum(1 for d in durations if lo <= d < hi)
print(f"{lo}-{hi if hi != float('inf') else ''}µs: {count} ({100*count/n:.1f}%)")
analyze_tail("/home/popertots/bench/pathfinding_benchmark_baseline_release.csv")
analyze_tail("pathfinding_benchmark_current.csv")
-1900
View File
File diff suppressed because it is too large Load Diff