-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation_benchmark.py
More file actions
79 lines (63 loc) · 2.77 KB
/
simulation_benchmark.py
File metadata and controls
79 lines (63 loc) · 2.77 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
import time
import os
from pathlib import Path
def simulate_compute(alpha_name):
# Simulate loading data and computing alpha
time.sleep(0.01) # Simulate some CPU work
return f"Results for {alpha_name}"
def baseline_io_and_compute(alphas):
os.makedirs("report_baseline", exist_ok=True)
start_time = time.time()
for alpha_name in alphas:
# Simulate IC Test (Compute + Output)
ic_output = simulate_compute(alpha_name)
# Simulate Group Test (Redundant Compute + Output)
group_output = simulate_compute(alpha_name)
report_path = Path("report_baseline") / f"{alpha_name}_report.txt"
with open(report_path, 'w') as f:
f.write("="*80 + "\n")
f.write(f"ALPHA TEST REPORT: {alpha_name}\n")
f.write("="*80 + "\n\n")
f.write(ic_output + "\n")
f.write(group_output + "\n")
end_time = time.time()
return end_time - start_time
def optimized_io_and_compute(alphas):
os.makedirs("report_optimized", exist_ok=True)
start_time = time.time()
master_report_path = Path("report_optimized") / "master_report.txt"
with open(master_report_path, 'w') as master_f:
master_f.write("MASTER ALPHA TEST REPORT\n")
master_f.write("="*80 + "\n\n")
for alpha_name in alphas:
# Shared computation (Done once)
shared_results = simulate_compute(alpha_name)
# Prepare report content in memory
report_content = "="*80 + "\n"
report_content += f"ALPHA TEST REPORT: {alpha_name}\n"
report_content += "="*80 + "\n\n"
report_content += shared_results + "\n"
report_content += shared_results + "\n" # Reusing results
# Write to individual report
report_path = Path("report_optimized") / f"{alpha_name}_report.txt"
with open(report_path, 'w') as f:
f.write(report_content)
# Write to master report
master_f.write(report_content)
master_f.write("\n\n")
end_time = time.time()
return end_time - start_time
if __name__ == "__main__":
alphas = [f"alpha{i:03d}" for i in range(1, 51)] # 50 alphas for testing
print(f"Running baseline simulation with {len(alphas)} alphas...")
baseline_time = baseline_io_and_compute(alphas)
print(f"Baseline Time: {baseline_time:.4f}s")
print(f"Running optimized simulation with {len(alphas)} alphas...")
optimized_time = optimized_io_and_compute(alphas)
print(f"Optimized Time: {optimized_time:.4f}s")
improvement = (baseline_time - optimized_time) / baseline_time * 100
print(f"Estimated Improvement: {improvement:.2f}%")
# Cleanup
import shutil
shutil.rmtree("report_baseline")
shutil.rmtree("report_optimized")