misc_performance.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Learning-Python-Application-Development 作者: PacktPublishing 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号