本文介绍了检查python中每行的运行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了一个 Python 脚本,但是运行它所花的时间比我预期的要长得多,而且我在脚本中没有明显的候选行占用运行时.
I've written a Python script, but running it is taking a lot longer than I had anticipated, and I've no obvious candidate for particuklar lines in the script taking up runtime.
是否可以在我的代码中添加任何内容来检查运行每行需要多长时间?
Is there anything I can put in my code to check how long its taking to run through each line?
非常感谢.
推荐答案你试过用分析运行 python 吗?
Have you tried running python with profiling?
python -m cProfile --sort cumulative your_single_thread_script.py &> out.log您可以在此问题中找到更多详细信息如何分析 Python 脚本?
You can find more details in this question How can you profile a python script?
您可以在此处阅读有关分析实用程序的更多信息.
You can read more about the profiling utility here.
更多推荐
检查python中每行的运行时间
发布评论