[Numpy-discussion] strange sin/cos performance

Andrew Friedley afriedle at indiana.edu
Mon Aug 3 10:08:42 EDT 2009


Thanks for the quick responses.

David Cournapeau wrote:
> On Mon, Aug 3, 2009 at 10:32 PM, Andrew Friedley<afriedle at 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 just ran on a PPC OSX 10.5 system:

sin float32 0.111793041229
sin float64 0.0902218818665
cos float32 0.112202882767
cos float64 0.0917768478394

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

>> 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?

>> 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.

Thanks for the pointer.

Andrew



More information about the NumPy-Discussion mailing list