Skip to content

Commit da45fef

Browse files
committed
compilation overhead slows us down
1 parent fa83807 commit da45fef

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

docs/kimon_prompts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@
5151

5252
1. I am considering using numba for optimization and faster runs in the HPC. Outline an implementation plan, practical considerations, and feasibility within a logical timeframe.
5353

54+
2. Walk me through modifying tg

scripts/macro_benchmark.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import time
2+
import statistics
3+
import logging
4+
from pathlib import Path
5+
import sys
6+
import numpy as np
7+
8+
# Ensure we can find our modules
9+
sys.path.insert(0, str(Path(__file__).parent.parent))
10+
11+
import scripts.pp_analysis as ppa
12+
from scripts.pp_analysis import Config
13+
14+
def run_stress_benchmark():
15+
cfg = Config()
16+
# INCREASE WORKLOAD: 150x150 grid and 1000 total steps
17+
# This ensures the 'race' is long enough to overcome the 'warmup'
18+
cfg.default_grid = 150
19+
cfg.n_prey_birth = 2 # 2x2 sweep is enough to see scaling
20+
cfg.n_prey_death = 2
21+
cfg.n_replicates = 3
22+
cfg.warmup_steps = 400
23+
cfg.measurement_steps = 600
24+
cfg.n_jobs = 4
25+
26+
output_dir = Path("results_stress")
27+
output_dir.mkdir(exist_ok=True)
28+
29+
logging.getLogger('scripts.pp_analysis').setLevel(logging.WARNING)
30+
31+
print("="*60)
32+
print("STRESS BENCHMARK: SCALING TO PRODUCTION SIZES")
33+
print("="*60)
34+
35+
# --- MODE A: NUMBA ENABLED ---
36+
print("[*] Running WITH Numba (Compiling + High-Speed Execution)...")
37+
ppa.USE_NUMBA = True
38+
t0 = time.perf_counter()
39+
ppa.run_2d_sweep(cfg, output_dir, logging.getLogger("test"))
40+
numba_total = time.perf_counter() - t0
41+
print(f" Total Time (Numba): {numba_total:.2f}s")
42+
43+
# --- MODE B: NUMBA DISABLED ---
44+
print("[*] Running WITHOUT Numba (Pure Python)...")
45+
ppa.USE_NUMBA = False
46+
t0 = time.perf_counter()
47+
ppa.run_2d_sweep(cfg, output_dir, logging.getLogger("test"))
48+
python_total = time.perf_counter() - t0
49+
print(f" Total Time (Python): {python_total:.2f}s")
50+
51+
# --- FINAL REPORT ---
52+
speedup = python_total / numba_total
53+
print("\n" + "="*60)
54+
print("STRESS BENCHMARK SUMMARY")
55+
print("="*60)
56+
print(f"Real-World Workflow Speedup: {speedup:.2f}x")
57+
print(f"Estimated time for 1000 sims in Python: {(python_total/12)*1000/3600:.1f} hours")
58+
print(f"Estimated time for 1000 sims in Numba: {(numba_total/12)*1000/3600:.1f} hours")
59+
print("="*60)
60+
61+
if __name__ == "__main__":
62+
run_stress_benchmark()

0 commit comments

Comments
 (0)