-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrace.py
More file actions
46 lines (38 loc) · 1.11 KB
/
race.py
File metadata and controls
46 lines (38 loc) · 1.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
#!/usr/bin/python3.8
from sys import argv
from time import time_ns
from fib import fib
from slowfib import slowfib
def run_fib(i):
race_one_start = time_ns()
race_one_results = fib(i)
race_one_finish = time_ns()
time_one = (race_one_finish - race_one_start) / 1e9
print(f">>> fib({i})")
print(f"{race_one_results}")
print(f" info: {fib.__doc__}")
print(f" time: {time_one} seconds\n")
def run_slowfib(i):
race_two_start = time_ns()
race_two_results = slowfib(i)
race_two_finish = time_ns()
time_two = (race_two_finish - race_two_start) / 1e9
print(f">>> slowfib({i})")
print(f"{race_two_results}")
print(f" info: {slowfib.__doc__}")
print(f" time: {time_two} seconds\n")
def main(i):
'''Race between fib functions'''
run_fib(i)
run_slowfib(i)
if (__name__ == '__main__'):
usage ='''usage: race (number of iterations between 0 and 498)'''
argc = len(argv)
if (argc >= 2):
cycles = int(argv[1])
if isinstance(cycles, int):
main(cycles)
else:
print(usage)
else:
print(usage)