Created
November 11, 2016 19:42
-
-
Save markostam/70086a5dcca84dbd869c9af1e2c9a169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
import timeit | |
# quicksort python | |
def quicksort(a): | |
if len(a) < 2: | |
return a | |
else: | |
pivot = a[int(len(a)/2)] | |
return (quicksort(list(filter(lambda x: x < pivot, a))) + | |
list(filter(lambda x: x == pivot, a)) + | |
quicksort(list(filter(lambda x: x > pivot, a)))) | |
# time testing | |
def test_quicksort(quicksort): | |
for power in range(1,7): | |
maxx = 10**power | |
a = [random.randint(0,maxx) for i in range(maxx)] | |
start_time = timeit.default_timer() | |
quicksort(a) | |
t = timeit.default_timer() - start_time | |
print('{:07.5f} for array size {}'.format(t,maxx)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment