line profiler 发表于 2022-06-23 分类于 python 介绍测量每一行代码运行次数,时间,百分比等。通过console调用,不想记python代码效率关系就用它。 安装1pip install line_profiler 调用github:(https://github.com/pyutils/line_profiler#:~:text=LineProfiler%20can%20be%20given%20functions%20to%20profile%2C%20and,every%20single%20line%20of%20code%20would%20be%20overwhelming.) 12345678910111213#在需要测量的def上一行标记一下@profile#在console内输入kernprof -l -v ./main.py#输出Line # #row numberHits #executed timesTime #total amount of time spent executing the line in the timer's unitsPer Hit #average amount of time spent executing the line% Time #percentage of time spent on that lineLine Contents #code content 注意事项使用@profile标记可能会报warning,不用管它直接console里运行就行。 计算出的time单位为1e-6s