Python time measure question (timeit)
vedrandekovic at yahoo.com
vedrandekovic at yahoo.com
Sun Feb 1 12:32:05 EST 2009
On 1 velj, 17:42, Steve Holden <st... at holdenweb.com> wrote:
> vedrandeko... 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/
Hello again,
This is the code that I ran:
a) Main code:
This code is in .exe:
t = Timer("import os;os.popen('python myscript.py arg1 2 3')")
print t.timeit()
b) myscript.py code:
import sys
print sys.argv[1]
var1=int(sys.argv[2])
var2=int(sys.argv[3])
var3=var1+var2
Regards,
John
More information about the Python-list
mailing list