[Numpy-discussion] strange sin/cos performance

David Cournapeau cournape@gmail....
Mon Aug 3 10:13:49 CDT 2009

On Mon, Aug 3, 2009 at 11:08 PM, Andrew Friedley<afriedle@indiana.edu> wrote:
> Thanks for the quick responses.
> David Cournapeau wrote:
>> 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 numbers above are on linux, RHEL 5.2.  The PS3 is running Fedora 9 I
> think.

I know next to nothing about the PS3 hardware, but I know that it is
quite different compared to conventional x86 CPU. Does it even have
both 4 and 8 bytes native  float ?

> Much more reasonable, but still not what I'd expect or what you seem to
> expect.

On a x86 system with sinf available in the math lib, I would expect
the float32 to be faster than float64. Other than that, the exact
ratio depends on too many factors (sse vs x87 usage, cache size,
compiler, math library performances). One order magnitude slower seems
very strange in any case.

>>> 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.
> I think linux has sinf, is there a quick/easy way to check if numpy is
> using it?

You can look at the config.h in numpy/core/include/numpy, and see if
there is a HAVE_SINF defined (for numpy >= 1.2.0 at least).



More information about the NumPy-Discussion mailing list