speedup up dictionary access
Courageous
jkraska1 at san.rr.com
Sat May 12 21:07:11 EDT 2001
On Sat, 12 May 2001 17:21:32 -0400, Roy Smith <roy at panix.com> wrote:
>One of the big time consumers in an application I'm writing is a cache
>lookup in the inner loop of the program. Right now, it looks something
>like this:
>
> if (self.cache.has_key (name) and self.cache[name]) or self.check (name):
> do stuff
Try
cache = self.cache
if (cache.has_key (name) and cache[name]) or self.check (name):
do stuff
You may also wish to ask yourself how likely the self.check() function is to
resolve to be true; if it's likely, put the check() call first.
C//
More information about the Python-list
mailing list