Concerns about performance w/Python, Pysco on Pentiums
Peter Hansen
peter at engcorp.com
Thu Mar 6 12:26:05 EST 2003
Michael Hudson wrote:
>
> "Anders J. Munch" <andersjm at dancontrol.dk> writes:
>
> > You were switching by means of a dict of functions, right? An elegant
> > and natural Python solution, but my bet is that psyco can't see
> > through it.
> >
> > Try replacing the dict with a long if-elif-elif-elif-chain ordered by
> > expected execution frequency. Or better yet, a tree of if statements
> > performing an inlined binary search, if you don't mind the
> > maintenance.
>
> You might also try a list of functions rather than a dict. I think
> psyco knows more about lists than dicts. But ICBW.
Ah, thanks. My lateral-thinking cap must have been off. Although
dicts are fast in Python in general, in this case the items in the
list are tightly constrained (opcodes, from 0 to 255) and a list
is quite feasible. I'll give it a shot - thanks! :)
-Peter
More information about the Python-list
mailing list