我的 Python 应用程序运行需要多长时间? [英] How long does my Python application take to run?

查看:36
本文介绍了我的 Python 应用程序运行需要多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我希望能够输出应用程序运行的经过时间.我想我需要使用某种 timeit 功能,但我不确定是哪一个.我正在寻找类似以下内容...

Basically, I want to be able to output the elapsed time that the application is running for. I think I need to use some sort of timeit function but I'm not sure which one. I'm looking for something like the following...

START MY TIMER
code for application
more code
more code
etc
STOP MY TIMER

OUTPUT ELAPSED TIME 在定时器的启动和停止之间执行上述代码.想法?

OUTPUT ELAPSED TIME to do the above code in between start and stop of timer. Thoughts?

推荐答案

最简单的方法是:

import time
start_time = time.time()

在开始和

print "My program took", time.time() - start_time, "to run"

最后.

这篇关于我的 Python 应用程序运行需要多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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