在Python中如何确定处理时间? [英] How do you determine a processing time in Python?
本文介绍了在Python中如何确定处理时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在java中,我会写:
long timeBefore = System.currentTimeMillis();
doStuff();
long timeAfter = System.currentTimeMillis();
已用时间= timeAfter - timeBefore;
我确信在Python中更容易。任何人都可以帮助?
解决方案
python中的等效项将是:
>>>进口时间
>>>> tic = time.clock()
>>>> toc = time.clock()
>>>>不好意思,你是怎么做的?你想找到最好的方法吗?那么你应该看看 timeit
。
I'm new to Python, and confused by the date/time documentation. I want to compute the time that it takes to perform a computation.
In java, I would write:
long timeBefore = System.currentTimeMillis();
doStuff();
long timeAfter = System.currentTimeMillis();
elapsed time = timeAfter - timeBefore;
I'm sure it's even easier in Python. Can anyone help?
解决方案 Equivalent in python would be:
>>> import time
>>> tic = time.clock()
>>> toc = time.clock()
>>> toc - tic
It's not clear what are you trying to do that for? Are you trying to find the best performing method? Then you should prob have a look at timeit
.
这篇关于在Python中如何确定处理时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文