Concerns about performance w/Python, Pysco on Pentiums

Peter Hansen peter at engcorp.com
Fri Mar 7 08:40:41 EST 2003


CezaryB wrote:
> 
> Tuples are faster then lists. Try this:
>         self.opcodes = tuple( Opcode.opcodes )

An interesting point, if true.  I'm surprised by that.  I would
have thought that the difference, if any, would be so small as
to be immeasurable in anything but code which only did tuple
lookups...  I'll have to experiment to see, if only to prove
your point to myself.

> >     def step(self):
> 
> >             if newPC is not None:
> >                 self.PC = newPC
> >             else:
> >                 self.PC += deltaPC + opcode.length
> >
> >             self.cycles += opcode.cycles
> >    ...
> Inline "step" in your main loop, use local variables instead od self.PC, self.opcodes
>   self.resolveAddress. It should help Psyco.

That's a possibility, of course, although then the step() method is
not available for use when I actually want it available, unless I
modify run() (which currently calls step()) so I can ask it to 
stop after only one instruction (and then rewrite step() to call
run() with that flag, of course).

If performance were really that important, these changes would be
exactly the route I would consider taking.  Performance isn't that
important, however, and maintainability is far more important than
the smallish gains that would be found so far.

I appreciate the suggestions, though, and may play with a few just
for kicks.

The real issue regarding Psyco for me was simply what I could get
*without* hand-tuning the code first.  In my mind, Psyco would 
provide negligible value if I could get significant speed gains
only by inlining code, using locals, and so forth.  What's needed
is something that lets me write the code in the most straight-
forward maintainable fashion, without much regard to performance
(except in basic algorithmic terms), and then slap in a bind()
or two and see a big speedup.  If that's not feasible, then I'm
personally happy with staying vanilla Python as it's lots 
"fast enough" in even this case.

But tuples faster than lists?  Hmmm.... ;-)

-Peter




More information about the Python-list mailing list