-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_time_compare.py
46 lines (38 loc) · 1.01 KB
/
exec_time_compare.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
35
36
37
38
39
40
41
42
43
44
45
46
from time import time
from fliton_fib_rs import fibonacci_number
from numba import jit
def python_fib_number(num: int) -> int:
if num < 0:
raise ValueError('Fibonacci should take parameter above 0')
elif num in [1, 2]:
return 1
else:
return python_fib_number(num - 1) + python_fib_number(num - 2)
@jit(nopython=True)
def numba_fib_number(num: int) -> int:
if num < 0:
raise ValueError('Fibonacci should take parameter above 0')
elif num in [1, 2]:
return 1
else:
return numba_fib_number(num - 1) + numba_fib_number(num - 2)
# python
python_fib_number(35)
t0 = time()
for i in range(20):
python_fib_number(35)
t1 = time()
print(f"the time taken for python is: {t1-t0}")
# numba
numba_fib_number(35)
t0 = time()
for i in range(20):
numba_fib_number(35)
t1 = time()
print(f"the time taken for numba is: {t1-t0}")
# rust
t0 = time()
for i in range(20):
fibonacci_number(35)
t1 = time()
print(f"the time taken for rust boosted python is: {t1-t0}")