#计时工具import time, sys, math
deffuncSqrt(x):return math.sqrt(x)
deffuncStars(x):return x ** 0.5deffuncPow(x):return pow(x, 0.5)
#重复100000次的总时间defmytime(func, num=10000, re=100000):if sys.platform =='win32':
start = time.clock()
else:
start = time.time()
for i in range(re):
res = func(num)
thetime = time.clock() - start
return thetime, res
#重复50次,取每1000次用时最小的值defmybest(func, times=50):
best = 2 * 32for i in range(times):
time, res = mytime(func,re=1000)
if best > time:
best = time
return best, res
print(sys.version)
for fun in (mytime, mybest):
print('=' * 40)
print('<%s>' % fun.__name__)
for func in (funcSqrt, funcStars, funcPow):
print('-' * 40)
print('%-10s>>> %.5f >>> %f' % (func.__name__, fun(func)[0], fun(func)[-1]))