Concerns about performance w/Python, Pysco on Pentiums

Andrew Bennetts andrew-pythonlist at puzzling.org
Fri Mar 7 03:24:04 EST 2003


On Fri, Mar 07, 2003 at 08:48:55AM +0100, Pedro Rodriguez wrote:
> On Thu, 06 Mar 2003 20:35:14 +0100, Peter Hansen wrote:
> 
> >     def step(self):
> >         opcodeByte = self.readByte(self.PC)
> >         try:
> >             opcode = self.opcodes[opcodeByte]
> >         except KeyError:
> >             raise UnimplementedOpcode('$%02X %s' % (opcodeByte,
> > self.readMemory(self.PC + 1, 5)))
> >         else:
> >             ...
> 
> if you are using a dictionnary for opcodes, wouldn't you gain
> time by not putting a try/except clause but by going straight
> with self.opcodes.get(...) and checking the returned value 
> against None.

Depends on how frequently the simulator attempts to lookup an non-existent
opcode.  My guess is that it would only happen rarely, in which case
try/except will be faster.

As always, the only way to know for sure is to try it on the actual code and
time it :)

-Andrew.






More information about the Python-list mailing list