[Tutor] Timing a loop
Ben Mazer
contrasutra at myrealbox.com
Wed Oct 22 16:41:18 EDT 2003
amk at amk.ca wrote:
> You want time.time(), which returns "wall clock" time. Your results will
> therefore vary depending on your system's load; if cron runs in the middle
> of your timing interval, you'll measure a longer time, so usually people
> make several runs, discard outliers, and average them.
> If you're using a big loop such as 'for i in range(100000)', you don't want
> to measure the time to create the list of 100000 integer objects, so you
> should write something like:
>
> L = range(100000)
> s = time.time()
> for i in L:
> ....
> e = time.time()
> print 'Total time:', e-s, 'sec'.
Thanks, that worked great. I can't believe I missed time.time().
:-D
--
/"\ Ben Mazer <contrasutra at myrealbox.com>
\ /
X ASCII RIBBON CAMPAIGN AGAINST HTML MAIL
/ \
More information about the Tutor
mailing list