-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.py
60 lines (47 loc) · 1.19 KB
/
sort_test.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
# -*- coding: utf-8 -*-
# from timeit import timeit as timeit
import time
import random
# 导入自己写的sort.oy
import sort
# 生成一个从1到1000的list
ls = list()
for i in range(1000):
ls.append(i)
# 分别用几种排序算法对其排序
# 排序之前,用random.shuffle将其打乱
# 冒泡排序
random.shuffle(ls)
time_start = time.clock()
sort.bubble_sort(ls)
print ("冒泡排序用时: % s" %(time.clock() - time_start) )
# 选择排序
random.shuffle(ls)
time_start = time.clock()
sort.select_sort(ls)
print ("选择排序用时: % s" %(time.clock() - time_start) )
# 插入排序
random.shuffle(ls)
time_start = time.clock()
sort.insert_sort(ls)
print ("插入排序用时: % s" %(time.clock() - time_start) )
# 希尔排序
random.shuffle(ls)
time_start = time.clock()
sort.shell_sort(ls)
print ("希尔排序用时: % s" %(time.clock() - time_start) )
# 归并排序
random.shuffle(ls)
time_start = time.clock()
sort.merge_sort(ls)
print ("归并排序用时: % s" %(time.clock() - time_start) )
# 快速排序
random.shuffle(ls)
time_start = time.clock()
sort.quick_sort(ls)
print ("快速排序用时: % s" %(time.clock() - time_start) )
# 堆排序
random.shuffle(ls)
time_start = time.clock()
sort.heap_sort(ls)
print ("堆排序用时: % s" %(time.clock() - time_start) )