Optimisation problem

Anton Vredegoor anton at vredegoor.doge.nl
Tue Nov 12 09:08:28 EST 2002


On Tue, 12 Nov 2002 15:44:28 +0800, "Simon Wittber (Maptek)"
<Simon.Wittber at perth.maptek.com.au> wrote:

<snip>

>Does anyone have any idea how I can optimise this code? It is going to
>be used in a very tight rendering loop. I would prefer to keep all the
>code in Python, and avoid writing any external modules.

<snip>

>	def __createMatrix(self):
>		self.matrix[0] = 1.0 - 2.0 * ( self.y * self.y + self.z
>* self.z )

Create local variables so that they can be found in the local scope of
the function:

m,x,y,z = self.matrix,self.x,self.y,self.z

This is faster and also saves typing. Creating local *functions* like
sin = math.sin is also a bit faster. Furthermore testing the effects
of speeding things up this way - using a speed test - is crucial. One
is toggling with the handles of a very complex machinery and the
results may be unpredictable.

Regards,
		Anton



More information about the Python-list mailing list