擅长:python、mysql、java
<p>如果您愿意考虑<code>timeit</code>的替代方案,我最近发现了<a href="http://code.google.com/p/7oars/wiki/StopWatch" rel="noreferrer">stopwatch</a>计时器实用程序,这可能对您的情况很有用。它也非常简单直观:</p>
<pre><code>import stopwatch
class TimedClass():
def __init__(self):
t = stopwatch.Timer()
# do stuff here
t.stop()
print t.elapsed
</code></pre>