python 代码性能分析

pip install line_profiler
def profile(func):
    from functools import wraps

    @wraps(func)
    def wrapper(*args, **kwargs):
        from line_profiler import LineProfiler
        prof = LineProfiler()
        try:
            return prof(func)(*args, **kwargs)
        finally:
            prof.print_stats()

    return wrapper

使用方式:

在要测试的函数上加装饰器

@profile
def funx():
    xxx
原文地址:https://www.cnblogs.com/guweixin/p/15097740.html