Language Shootout

Malcolm Tredinnick malcolm at commsecure.com.au
Mon Jul 9 23:53:35 EDT 2001


On Tue, Jul 10, 2001 at 02:26:44AM +0000, Paul Winkler wrote:
> Fredrik Lundh wrote:
> > does your fastest iterative solution beat this one?
> 
> That's pretty fast, once I got it to work... but still not as fast as
> my best one. Yours iis definitely interesting, largely because I
> don't understand what the hell it does. If I rename one of the fibs
> and change the appropriate call to use the new name, it still computes
> fibonacci numbers but performance goes way down as N rises. So you're
> somehow relying on the duplicated names for speed. That's a pretty
> weird optimization technique.

Ooh, ooh ... I know this one. :-)

It's a scoping trick (and it really is a "trick" here, because the same
name is being used and this leads to a bit of confusion).

/F's solution makes sure that the code objcet of the first 'fib' is in
the local namespace of the second 'fib' function. This speeds up lookups
to it significantly (local variables are implemented as a dictionary,
globals are not).

Does that make it understandable (I could rabbit on a lot further, but
why spoil all the fun)?

Cheers,
Malcolm

-- 
Honk if you love peace and quiet.




More information about the Python-list mailing list