-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_object.py
41 lines (30 loc) · 1.11 KB
/
benchmark_object.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
from fliton_fib_rs import FibProcessor
import time
class PythonFibProcessor:
def __init__(self, number, numbers):
self.number = number
self.numbers = numbers
self.numbers_results = None
self.number_results = None
self._process()
def _process(self):
self.numbers_results = [
self.calculate_numbers(i) for i in self.numbers]
self.number_results = self.calculate_numbers(self.number)
def fibonacci_number(self, number):
if number < 0:
return None
elif number <= 2:
return 1
else:
return self.fibonacci_number(number - 1) + self.fibonacci_number(number - 2)
def calculate_numbers(self, numbers):
return [self.fibonacci_number(i) for i in numbers]
t_one = time.time()
test = FibProcessor([11, 12, 13, 14], [[11, 12], [13, 14], [15, 16]])
t_two = time.time()
print(f"Run with Rust Python object:", t_two - t_one)
t_one = time.time()
test = PythonFibProcessor([11, 12, 13, 14], [[11, 12], [13, 14], [15, 16]])
t_two = time.time()
print(f"Run with python object:", t_two - t_one)