Last active
May 5, 2020 17:45
-
-
Save MartinPicc/881a95dc86682cfc5f9a66134c258def to your computer and use it in GitHub Desktop.
fichier de test pour différentes implémentations de quicksort - np.sort et pur python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import default_timer as timer | |
from copy import copy | |
import numpy as np | |
# Test parameters | |
array_size = 10000 # size of test array | |
repeat = 5 # numbers of arrays to test | |
n_iter = 100 # number of tests for each array | |
functions = { | |
"fonction numpy.sort": lambda x: np.sort(x, kind='quicksort'), | |
"Python pur": lambda x: quicksort(x), | |
} | |
times = {k: 0 for k in functions.keys()} | |
# make tests | |
for i in range(repeat * n_iter): | |
if i % n_iter == 0: # initiate random array of size array_size if i is a multiple of n_iter | |
array = np.random.rand(array_size) | |
for f_name, f in functions.items(): | |
start = timer() | |
f(copy(array)) # make a copy to avoid changing the original array | |
times[f_name] += (timer() - start) * 1000 / (repeat * n_iter) # store execution time in ms | |
# Print results | |
print(f"Test sur {repeat} listes aléatoires de taille {array_size}, {n_iter} itérations à chaque fois :") | |
for f_name, t in times.items(): | |
print(f"\t{np.round(t, 2)} ms par tri pour : {f_name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment