Concerns about performance w/Python, Pysco on Pentiums
Peter Hansen
peter at engcorp.com
Fri Mar 7 08:34:30 EST 2003
Andrew Bennetts wrote:
>
> 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.
Andrew is quite right. Naturally, unimplemented opcodes are in effect
*never* encountered in valid code, and that feature is there for now
only because 34 out of about 200 opcodes have been implemented.
-Peter
More information about the Python-list
mailing list