Concerns about performance w/Python, Pysco on Pentiums

CezaryB cezary at bigfoot.com
Fri Mar 7 05:26:38 EST 2003


On 3/6/03 8:35 PM, Peter Hansen wrote:
> Michael Hudson wrote:
> 
>>Peter Hansen <peter at engcorp.com> writes:

> Interesting...  I tried the (one-line!) change to use a list 
> instead of a dict...  below are some results.  For reference, for those 
> still interested, here are a few snippets showing sample code, with some
> extraneous stuff removed for clarity:
[...]
> class Cpu:
>    ....
>     def __init__(self, name):
>         self.name = name
> 
>         self.setCCR('sxhinzvc')
>         self.D = 0
>         self.A = 0
>         self.B = 0
>         self.X = 0
>         self.Y = 0
>         self.SP = 0
>         self.PC = 0
>         self.memory = [0] * 65536
>         self.opcodes = Opcode.opcodes
Tuples are faster then lists. Try this:
	self.opcodes = tuple( Opcode.opcodes )

>     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:
>             deltaPC, self.effectiveAddress = self.resolveAddress(opcode.mode)
>             newPC = opcode.execute(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.

CezaryB






More information about the Python-list mailing list