[Numpy-discussion] strange sin/cos performance

David Cournapeau cournape@gmail....
Mon Aug 3 08:44:28 CDT 2009

On Mon, Aug 3, 2009 at 10:32 PM, Andrew Friedley<afriedle@indiana.edu> wrote:
> While working on GSoC stuff I came across this weird performance behavior
> for sine and cosine -- using float32 is way slower than float64.  On a 2ghz
> opteron:
> sin float32 1.12447786331
> sin float64 0.133481025696
> cos float32 1.14155912399
> cos float64 0.131420135498

Which OS are you on ? FWIW, on max os x, with recent svn checkout, I
get expected results (float32 ~ twice faster).

> The times are in seconds, and are best of three runs of ten iterations of
> numpy.{sin,cos} over a 1000-element array (script attached).  I've produced
> similar results on a PS3 system also.  The opteron is running Python 2.6.1
> and NumPy 1.3.0, while the PS3 has Python 2.5.1 and NumPy 1.1.1.
> I haven't jumped into the code yet, but does anyone know why sin/cos are
> ~8.5x slower for 32-bit floats compared to 64-bit doubles?

My guess would be that you are on a platform where there is no sinf,
and our sinf replacement is bad for some reason.

> Side question:  I see people in emails writing things like 'timeit foo(x)'
> and having it run some sort of standard benchmark, how exactly do I do that?
>  Is that some environment other than a normal Python?

Yes, that's in ipython.



More information about the NumPy-Discussion mailing list