[Tutor] Astonishing timing result

Dick Moores rdm at rcblue.com
Tue Jun 24 22:44:00 CEST 2008


At 12:44 PM 6/24/2008, Kent Johnson wrote:
>On Tue, Jun 24, 2008 at 1:43 PM, Dick Moores <rdm at rcblue.com> 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




More information about the Tutor mailing list