检查python中每行的运行时间

编程入门 行业动态 更新时间:2024-10-26 10:28:20
本文介绍了检查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中每行的运行时间

本文发布于:2023-11-30 21:38:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!