检查python中每行的运行时间 [英] Check running time per line in python

查看:81
本文介绍了检查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中每行的运行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆