[CentralOH] Python interpretor question

William McVey wam at cisco.com
Thu Apr 21 16:02:01 CEST 2011


On Wed, 2011-04-20 at 20:35 -0400, Eric Floehr wrote:
> One million executions of f1 to 0.65 seconds on my machine, f2 took
> 0.62 seconds.  This holds regardless if I test f2 or f1 first, etc.
> 
> 
> So Jon's thought that the local variable create/destroy weighing down
> f1 more than the time benefit of a function-space lookup seems to
> hold.
> 
I'd warn about extrapolating too much from this one limited example.
Although the creation of a single use variable multiple times within the
function caused f1 to take more computation than f2, if the variable is
referenced more than just once, the value of a local lookup within the
function's namespace will begin to shine through and "pay off" the
variable's creation cost. Some simplistic testing showed that after 3
lookups within the functions, f1 began running faster than f2.

  -- William




More information about the CentralOH mailing list