import timeit def base_func2(): for n in range(10000): print('当前n的值是:{}'.format(n)) res = timeit.timeit(base_func2,number=5) print('当前的函数的运行时间是:{}'.format(res))
def base_func3(): for n in range(10000): print('当前n的值是:{}'.format(n)) from line_profiler import lineprofiler lp = lineprofiler() lp_wrap = lp(base_func3) lp_wrap() lp.print_stats() # line # hits time per hit % time line contents # ============================================================== # 72 def base_func3(): # 73 10001 162738.0 16.3 4.8 for n in range(10000): # 74 10000 3207772.0 320.8 95.2 print('当前n的值是:{}'.format(n))
# pip install heartrate import heartrate heartrate.trace(browser=true) def base_func4(): for n in range(10000): print('当前n的值是:{}'.format(n))
运行以后,控制台打印如下日志:
# * serving flask app "heartrate.core" (lazy loading) # * environment: production # warning: this is a development server. do not use it in a production deployment. # use a production wsgi server instead. # * debug mode: off