-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbenchmark.py
More file actions
36 lines (27 loc) · 982 Bytes
/
benchmark.py
File metadata and controls
36 lines (27 loc) · 982 Bytes
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
#!/usr/bin/env python
"""Benchmark script to compare Python vs Cython performance."""
import time
import sys
from pytrim.simulation import TRIMSimulation, SimulationParameters, is_using_cython
def benchmark(n_ions=1000):
"""Run benchmark with given number of ions."""
params = SimulationParameters()
params.nion = n_ions
sim = TRIMSimulation(params)
print(f"Running benchmark with {n_ions} ions...")
print(f"Using {'Cython' if is_using_cython() else 'Python'} modules")
print("-" * 50)
start = time.time()
results = sim.run()
end = time.time()
print(results.get_summary())
print("-" * 50)
ions_per_second = n_ions / (end - start)
print(f"Performance: {ions_per_second:.1f} ions/second")
print(f"Time per ion: {(end - start) / n_ions * 1000:.2f} ms")
return end - start
if __name__ == '__main__':
n = 1000
if len(sys.argv) > 1:
n = int(sys.argv[1])
benchmark(n)