You'll see three sections, plus some prints down below to get the results. The 3 are t1, t2, and t3. t2 has the sorting function the list helped me write yesterday, sort_tuple_list_by_2nd_elements(). t1 has the code of the function, but is not a function. t3 is exactly the same as t2, except that the function is imported from a module, mycalc.py, in which I have many functions I've written or stolen.
I'll repeat the output here:
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!
Comments? Enlightenment?
Dick Moores
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor