1 #-*- encoding= utf-8 -*- 2 from random import randint 3 import datetime 4 5 s=[] 6 7 for i in range(0,10000): 8 s.append(randint(1,10000)) 9 10 #排序算法 11 def sort_list(list): 12 for i in range(len(list)-1): 13 index = i 14 for j in range(i + 1, len(list)): 15 if list[index] > list[j]: 16 index = j 17 list[i], list[index] = list[index], list[i] 18 19 #冒泡算法 20 def bubble_sort(list): 21 for i in range(len(list)-1): 22 for j in range(len(list)-1-i): 23 if list[j]>list[j+1]: 24 list[j],list[j+1]=list[j+1],list[j] 25 26 27 starttime=datetime.datetime.now() 28 sort_list(s) 29 endtime=datetime.datetime.now() 30 print (endtime-starttime).seconds 31 32 print s