On Tue, June 24, 2008 2:06 pm, [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?
Does this mean that if __name__ == "__main__" takes the extra time? and that that's brings t2 in line with the others? and that the difference represents the time it takes to set up a code-block? Something like that? Marilyn Davis >> >> >> Dick >> > > > Hey Dick, > > > I'm not too clear on what it is that you want explained. > > > 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>). > > > I'd further wager that if you repeat the timing a few times, you'll > find that on some runs t2 is less than t3. > > Best, > > > Brian vdB > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor