Monte Carlo Method and pi
tim.hochberg at ieee.org
Tue Jul 13 05:37:43 CEST 2004
beliavsky at aol.com wrote:
> Tim Hochberg <tim.hochberg at ieee.org> wrote:
>>If one takes into the accout the speed difference of the two CPUs this
>>puts the both the numarray and psyco solutions within about 50% of the
>>Fortran solution, which I'm impressed by. Of course, the Fortran code
>>uses x**2 instead of x*x, so it too, might be sped by some tweaks.
> With Compaq Visual Fortran, the speed with x**2 and x*x are the same. Recently
> on comp.lang.fortran, a Fortran expert opined that a compiler that did not
> optimize the calculation of integer powers to be as fast as the hand-coded
> equivalent would not be taken seriously.
I suppose that's not suprising. In that case, I'm more impressed with
the psyco results than I was. Particularly since Psycos floating point
support is incomplete.
> Having to write out integer powers in Python is awkward, although the performance
> improvement may be worth it. The code x*x*x*x is less legible than x**4,
> especially if 'x' is replaced 'longname[1,2,3]'.
I think that this is something that Psyco could optimize. However,
currently psyco just punts on pow, passing it off to Python.
> Often, what you want to compute powers of is itself an expression. Is Python
> with Psyco able to run code such as
> z = sin(x)*sin(x)
> as fast as
> y = sin(x)
> z = y*y ?
Dunno. I'll check...
> Does it make two calls to sin()? There is a performance hit for 'y = sin(x)*sin(x)'
> when not using Psyco.
It appears that it does not make this optimization. I suppose that's not
suprising since my understanding is that Psyco generates really simple
More information about the Python-list