使用timeit。多次运行测试会给我带来更好的结果。
func_list=[locals()[key] for key in locals().keys() if callable(locals()[key]) and key.startswith('time')]alist=range(1000000)times=[]for f in func_list: n = 10 times.append( min( t for t,_,_ in (f(alist,31) for i in range(n))))for (time,func_name) in zip(times, func_list): print '%s took %0.3fms.' % (func_name, time*1000.)
->
<function wrapper at 0x01FCB5F0> took 39.000ms.<function wrapper at 0x01FCB670> took 41.000ms.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)