-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_comparison.py
36 lines (27 loc) · 1.06 KB
/
time_comparison.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
import time
import sympy
import prime_functions
import primality_test
def time_comparison(func_list, input):
results = []
print('----------------------------------------')
print(f'Comparing function "{func_list[0].__name__}({input})"')
print('----------------------------------------')
for func in func_list:
start = time.time()
results.append(func(input))
end = time.time()
print(f'{func.__module__} took {end - start} seconds')
print('----------------------------------------')
if all(x == results[0] for x in results):
print(f'All results are equal: {results[0]}')
else:
print(f'Not all results are equal: {results}')
print('----------------------------------------')
def main():
# isprime(n) time comparison
time_comparison([prime_functions.isprime, sympy.isprime, primality_test.isprime], 2147483647)
# for bigger numbers we can't use prime_functions.isprime
time_comparison([sympy.isprime, primality_test.isprime], 2305843009213693951)
if __name__ == '__main__':
main()