/
__init__.py
66 lines (43 loc) · 1.11 KB
/
__init__.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
56
57
58
59
60
61
62
63
64
65
# Std Lib
import time
# sort imports
from bubble import bubble_sort, short_bubble_sort
from selection import selection_sort
from insertion import insertion_sort
from shell import shell_sort
from merge import merge_sort
from quick import quick_sort
def print_time(function):
def wrapper(*args):
"""Wrapper calculates time taken by each function, prints result, then returns sorted list as normal."""
time_before = time.clock()
result = function(*args)
time_after = time.clock()
print "{func_name} sort sorted {length} items in {time} seconds".format(
func_name=function.func_name,
length=len(result),
time=(time_after - time_before)
)
return result
return wrapper
@print_time
def bubble(*args):
return bubble_sort(*args)
@print_time
def short_bubble(*args):
return short_bubble_sort(*args)
@print_time
def selection(*args):
return selection_sort(*args)
@print_time
def insertion(*args):
return insertion_sort(*args)
@print_time
def shell(*args):
return shell_sort(*args)
@print_time
def merge(*args):
return merge_sort(*args)
@print_time
def quick(*args):
return quick_sort(*args)