-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_add_vector.py
55 lines (38 loc) · 1.4 KB
/
benchmark_add_vector.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
47
48
49
50
51
52
53
54
55
from fliton_fib_rs import time_add_vectors
import numpy as np
import matplotlib.pyplot as plt
import time
def rust_function(total_vector_size: int) -> float:
t1 = time.time()
sum_vector = time_add_vectors(total_vector_size)
result = time.time() - t1
if result > 0.00001:
result = 0.00001
return result
def numpy_function(total_vector_size: int) -> float:
t1 = time.time()
first_vector = np.arange(total_vector_size)
second_vector = np.arange(total_vector_size)
sum_vector = first_vector + second_vector
result = time.time() - t1
if result > 0.00001:
result = 0.00001
return result
def python_function(total_vector_size: int) -> float:
t1 = time.time()
first_vector = range(total_vector_size)
second_vector = range(total_vector_size)
sum_vector = [first_vector[i] + second_vector[i]
for i in range(len(second_vector))]
result = time.time() - t1
if result > 0.00001:
result = 0.00001
return result
numpy_results = [numpy_function(i) for i in range(0, 200)]
rust_results = [rust_function(i) for i in range(0, 200)]
python_results = [python_function(i) for i in range(0, 200)]
plt.plot(rust_results, linestyle='solid', color="green")
plt.plot(python_results, linestyle='solid', color="red")
plt.plot(numpy_results, linestyle='solid', color="blue")
# plt.show()
plt.savefig("benchmark_add_vector.png")