defmy_decorator(func):defwrapper(*args,**kwargs):print("Before function call")result = func(*args,**kwargs)print("After function call")return resultreturn wrapper@my_decoratordefsay_hello():print("Hello!")say_hello()
defbubble_sort(arr):n =len(arr)for i inrange(n):for j inrange(0, n - i -1):if arr[j]> arr[j +1]:arr[j], arr[j +1]= arr[j +1], arr[j]return arr
快速排序:
defquick_sort(arr):iflen(arr)<=1:return arrpivot = arr[0]left =[x for x in arr[1:]if x <= pivot]right =[x for x in arr[1:]if x > pivot]return quick_sort(left)+[pivot]+ quick_sort(right)
FFTW(Fastest Fourier Transform in the West)是世界上最快的FFT, 实测计算长度为10000的double数组, 单次运行时间在2ms左右。为了详细了解FFTW以及为编程方便,特将用户手册看了一下,并结合手册制作了以下…