[Tutor] Time

Steven D'Aprano steve at pearwood.info
Wed Jun 23 13:14:34 CEST 2010


On Wed, 23 Jun 2010 11:11:32 am Dave Angel wrote:

> If you're really looking to measure performance, you should use the
> timeit module.  But for simply deciding how much time has elapsed
> between two points in your code, you can use the time.time()
> function.
>
> import time
>
> start = time.time()
> ...  do some work
> end = time.time()-start


Just to re-iterate what Dave said, don't use this technique for timing 
small code snippets, it isn't accurate enough to give meaningful 
results. For that, use timeit. 

But for reporting how long some big chunk of work took, that's perfectly 
fine, e.g. if you expect to print something like this:

"Processed 1734 records in 8.2 seconds."


-- 
Steven D'Aprano


More information about the Tutor mailing list