Python time measure question (timeit)

Steve Holden steve at holdenweb.com
Sun Feb 1 11:42:37 EST 2009


vedrandekovic at yahoo.com wrote:
> Hello,
> 
> When I run following code with os.popen  (for this time measure I'm
> using python module timeit):
> 
> 
> for i in range(50):
>     print i
> 
> 
> I get this result:  0.00246958761519
> 
> 
> But when I run same code from IDLE i get this result:
> 6.4533341528e-005
> 
> 
> now, I have two questions:
>               1) Which of this results is correct?

Both are. What makes you think that printing in IDLE (to a GUI) should
take the same amount of time as it does "running with os.popen (whatever
that means). The two environments are likely to be completely different,
but you haven't show the exact code you ran so it's hard to be more exact.

>               2) Are this results in micro seconds?
> 
No, seconds, as it says in the documentation:

"""This executes the setup statement once, and then returns the time it
takes to execute the main statement a number of times, measured in
seconds as a float""".

Even a modern computer doesn't do much in .0024 microseconds.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list