Hello everyone.
I wrote my own test module, which is responsible for measuring the timing of algorithms, I used it mainly for sorting algorithms this is so to say a very early beta version, which I would like to expand with various functionalities, in general I would like to take care of the appearance of the code. I look forward to your opinions and comments, possibly your own ideas.
So here is my testing_module code:
import random
import matplotlib.pyplot as plt
accident = ["x", "random.randint(1, 100)", "x"]
history = ["Optimistic", "Average", "Pessimistic"]
def make_data(numbers, y):
data = []
for element in numbers:
data.append([eval(accident[y]) for x in range(element)])
return data
def make_plot(numbers, measures, name):
for x in range(3):
plt.plot(numbers, measures[x], label = history[x])
plt.title(name)
plt.legend()
plt.show()
def test(method, numbers, measures):
name_function = method.__name__
for x in range(3):
if x != 2:
for element in make_data(numbers, x):
method(element, x)
else:
for element in make_data(numbers, x):
element.reverse()
method(element, x)
make_plot(numbers, measures, name_function)
And this is how i was using it in my code:
import testing_module as test
import time
measures = [[], [], []]
numbers = [10, 100, 300, 500, 700]
def insertion_sort(array, x=0):
start = time.time()
for j in range(1, len(array)):
key = array[j]
i = j - 1
while (i > -1) and key < array[i]:
array[i + 1] = array[i]
i = i - 1
array[i + 1] = key
end = time.time()
measures[x].append(end - start)
test.test(insertion_sort, numbers, measures)
Thanks in advance for any tips and ideas how to improve my solution. Have a great day!