今天看《python科学计算》学习到的平方根倒数速算法这里实践并记录:
由于刚刚接触py不久,首先查了一下自定义函数用timeit模块计算时间性能的用法如下,
1 import random 2 import timeit 3 from time import clock 4 5 6 def get_random_number(num): 7 '''get random number, no repeated element; use random.sample() method''' 8 return random.sample(range(num), num) 9 10 11 if __name__ == "__main__": 12 #use clock() method to calculate time 13 start = clock() 14 list_a = get_random_number(200) 15 finish = clock() 16 print(finish -