At 02:06 PM 6/24/2008, [EMAIL PROTECTED] wrote:
----- Message from [EMAIL PROTECTED] ---------
Date: Tue, 24 Jun 2008 13:44:00 -0700
From: Dick Moores <[EMAIL PROTECTED]>
At 12:44 PM 6/24/2008, Kent Johnson wrote:
On Tue, Jun 24, 2008 at 1:43 PM, Dick Moores <[EMAIL PROTECTED]> wrote:
Output:
t1 is 0.000104, no function
t2 is 5.87e-006, function explicit
t3 is 0.000126, function imported
t1/t2 is 17.8
t1/t3 is 0.827
t3/t2 is 21.5
Now, I'd heard that code in a function runs faster than the same
code not in
a function, but even so I was surprised at the t1/t2 ratio of 17.8.
The astonishing (to me, anyway) result was the t3/t2 ratio. I had no idea
that importing from mycalc slowed a script down at all, let alone by a
factor of 21!
Note that t1 and t3 are pretty close to each other. Perhaps you should
be suspicious of t2. What if __name__ != '__main__' ?
With that,
t1 is 0.000104, no function
t2 is 0.000117, function explicit
t3 is 0.000113, function imported
t1/t2 is 0.885
t1/t3 is 0.914
t3/t2 is 0.969
Explain?
Dick
Hey Dick,
I'm not too clear on what it is that you want explained.
Well, Kent suggested trying if __name__ != '__main__' . Why would
that make such a difference?
It seems to me that the difference between t2 and t3 is 1) is so small
as to be most likely due to (effectively) random fluctuations of your
environment (the demands that other processes were making on your
system at the time) and 2) so small so as to not be worth worrying
about (<http://c2.com/cgi/wiki?PrematureOptimization>).
Basically, I'm not worried, just curious. Not about the small
differences, but why did the use of the standard if __name__ ==
'__main__' result it such speed? This was not a fluke. Before
posting, I got similar results with different functions, albeit not
quite as extreme.
Am I not doing the timing correctly?
Dick
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor