冒泡排序加装饰器算时间
2021-09-06 本文已影响0人
铁甲依然在人间
import time
def runtime(func):
def wrapper(*args,**kwargs):
start=time.perf_counter()
func(*args,**kwargs)
end =time.perf_counter()
print(end -start)
return wrapper
@runtime
def dubble_sort(L):
for i in range(1,len(L)):
for j in range(0,len(L)-i):
if L[j]>L[j+1]:
L[j],L[j+1]=L[j+1],L[j]
return L
if __name__ == '__main__':
array = [10, 17, 50, 7, 30, 24, 27, 45, 15, 5, 36, 21]
(dubble_sort(array))