Optimisation problem
Michael Hudson
mwh at python.net
Tue Nov 12 10:50:44 EST 2002
anton at vredegoor.doge.nl (Anton Vredegoor) writes:
> 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
Don't be so sure: this creates a tuple.
m = self.matrix; x = self.x; ... etc
is quicker.
> and also saves typing.
But more typing.
> 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.
This is of course very good advice.
Cheers,
M.
--
I believe C++ instills fear in programmers, fear that the
interaction of some details causes unpredictable results.
-- Erik Naggum, comp.lang.lisp
More information about the Python-list
mailing list