-
Notifications
You must be signed in to change notification settings - Fork 8
/
timing.py
34 lines (28 loc) · 926 Bytes
/
timing.py
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
import os
import sys
from time import perf_counter
def time_both(n):
time_python(n)
time_cpp(n)
def time_python(n):
t_start = perf_counter()
os.system(f"python ./nbody.py {n}")
t_stop = perf_counter()
print(f"Running time python program: {(t_stop - t_start)} sec")
def time_cpp(n):
t_start = perf_counter()
os.system(f"./nbody {n}")
t_stop = perf_counter()
print(f"Running time C++ program: {(t_stop - t_start)} sec")
if __name__ == "__main__":
if len(sys.argv) >= 2:
n = int(sys.argv[1])
if len(sys.argv) > 2 and sys.argv[2] == "python":
time_python(n)
elif len(sys.argv) > 2 and (sys.argv[2] == "c++" or sys.argv[2] == "cpp"):
time_cpp(n)
elif len(sys.argv) > 2 and sys.argv[2] == "pythonall":
for i in [5000,500000,5000000,50000000]:
time_python(i)
else:
time_both(n)