forked from ChuyueSun/VeriStruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_bench_no_cache.py
More file actions
executable file
·126 lines (106 loc) · 4.11 KB
/
Copy pathrun_bench_no_cache.py
File metadata and controls
executable file
·126 lines (106 loc) · 4.11 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
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
Run benchmarks with cache disabled for accurate runtime statistics.
"""
import argparse
import glob
import os
import subprocess
import time
def main():
parser = argparse.ArgumentParser(
description="Run benchmarks with LLM cache disabled (for accurate cost/time statistics)",
epilog="""Examples:
Single benchmark without cache:
python run_bench_no_cache.py --configs config-azure --benchmark vectors_todo
All benchmarks without cache:
python run_bench_no_cache.py --configs config-azure
Note: This disables LLM cache to measure true API costs and response times.
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--configs",
nargs="+",
default=["config-azure"],
help="One or more config names (without .json), e.g., 'config-azure'",
metavar="NAME",
)
parser.add_argument(
"--benchmark",
help="Benchmark name only (e.g., 'vectors_todo'). Omit to run all benchmarks.",
metavar="NAME",
)
args = parser.parse_args()
# Prepare output directory (preserve existing content)
os.makedirs("output", exist_ok=True)
# Determine which benchmarks to run
if args.benchmark:
# Validate that the benchmark exists
todo_file = f"benchmarks-complete/{args.benchmark}.rs"
if not os.path.exists(todo_file):
print(f"Error: Benchmark '{args.benchmark}' not found. Expected file: {todo_file}")
print("Available benchmarks:")
for todo_path in glob.glob("benchmarks-complete/*_todo.rs"):
name = os.path.splitext(os.path.basename(todo_path))[0]
print(f" - {name}")
return
benchmarks = [args.benchmark]
print(f"Running individual benchmark: {args.benchmark}")
else:
# Run all benchmarks
benchmarks = []
for todo_path in glob.glob("benchmarks-complete/*_todo.rs"):
name = os.path.splitext(os.path.basename(todo_path))[0]
benchmarks.append(name)
print(f"Running all benchmarks: {len(benchmarks)} found")
for cfg in args.configs:
cfg_results_root = os.path.join("output", cfg)
os.makedirs(cfg_results_root, exist_ok=True)
# Prepare all benchmarks and start them in parallel
processes = []
log_files = []
for benchmark_name in benchmarks:
test_file = f"benchmarks-complete/{benchmark_name}.rs"
bench_dir = os.path.join(cfg_results_root, benchmark_name)
os.makedirs(bench_dir, exist_ok=True)
log_file = os.path.join(bench_dir, "output.log")
log_files.append(log_file)
print(f"Starting {benchmark_name} with {cfg} (cache disabled) -> log: {log_file}")
# Set environment to disable cache
env = os.environ.copy()
env["ENABLE_LLM_CACHE"] = "0"
cmd = [
"./run_agent.py",
"--test-file",
test_file,
"--no-cache-read",
"--output-dir",
bench_dir,
"--immutable-functions",
"test",
"--num-repair-rounds",
"10",
]
# Open log file and start process
log_handle = open(log_file, "w")
proc = subprocess.Popen(
cmd,
env=env,
stdout=log_handle,
stderr=subprocess.STDOUT,
text=True,
)
processes.append((benchmark_name, proc, log_handle))
print(f"\n✓ Started {len(processes)} benchmarks in parallel")
print("Waiting for all benchmarks to complete...\n")
# Wait for all processes to complete
for benchmark_name, proc, log_handle in processes:
proc.wait()
log_handle.close()
if proc.returncode == 0:
print(f" ✓ Completed {benchmark_name}")
else:
print(f" ✗ Error running {benchmark_name} (exit code: {proc.returncode})")
if __name__ == "__main__":
main()