def run_timeit(func_1, func_2, num=1):
"""Run timeit.timeit for the given function names (input args)
.. todo:: Make this function robust by handling errors due to incorrect
function names.
.. todo:: You could also refactor this function and pass the whole
function as an argument. Then you can extract the function name string
as function.__name__
"""
t1 = timeit.timeit("%s()"%func_1,
setup="from __main__ import %s"%func_1, number=num)
t2 = timeit.timeit("%s()"%func_2,
setup="from __main__ import %s"%func_2, number=num)
print("Function: {func}, time: {t}".format(func=func_1, t=t1))
print("Function: {func}, time: {t}".format(func=func_2, t=t2))
print("~"*40)
misc_performance.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录