-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_benchmark.sh
More file actions
executable file
·58 lines (41 loc) · 1.15 KB
/
new_benchmark.sh
File metadata and controls
executable file
·58 lines (41 loc) · 1.15 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
#!/usr/bin/env bash
set -euo pipefail
# Usage: ./new_benchmark.sh <name>
# Example: ./new_benchmark.sh dict_vs_list
if [[ $# -lt 1 ]]; then
echo "Usage: ./new_benchmark.sh <name>"
exit 1
fi
name=$1
file="benchmarks/${name}_benchmark.py"
mkdir -p benchmarks
cat > "$file" << 'EOF'
"""
<BenchmarkName> Benchmark
This benchmark compares multiple approaches for the same operation.
Each entry in the `tests` dictionary defines a named approach
that will be included in the summary table automatically.
"""
import platform
import timeit
def run_benchmark() -> None:
N = 1_000_000
setup_code = """
# Place any setup code here
data = [i for i in range(100)]
"""
tests = {
"Approach A": "sum(data)",
"Approach B": "[x * 2 for x in data]",
}
print(f"Benchmark: <BenchmarkName>_benchmark.py")
print(f"Python: {platform.python_version()}")
for name, stmt in tests.items():
t = timeit.timeit(stmt, setup=setup_code, number=N)
print(f"{name}: {t:.6f}")
if __name__ == "__main__":
run_benchmark()
EOF
sed -i "s/<BenchmarkName>/${name^}/" "$file"
chmod +x "$file"
echo "✅ Created benchmark template: $file"