[Numpy-discussion] strange sin/cos performance

Charles R Harris charlesr.harris@gmail....
Tue Aug 4 12:48:34 CDT 2009


On Tue, Aug 4, 2009 at 11:19 AM, Andrew Friedley <afriedle@indiana.edu>wrote:

> David Cournapeau wrote:
> > On Wed, Aug 5, 2009 at 12:14 AM, Andrew Friedley<afriedle@indiana.edu>
> wrote:
> >
> >> Do you know where this conversion is, in the code?  The impression I got
> >> from my quick look at the code was that a wrapper sinf was defined that
> >> just calls sin.  I guess the typecast to float in there will do the
> >> conversion
> >
> > Exact. Given your CPU, compared to my macbook, it looks like the
> > float32 is the problem (i.e. the float64 is not particularly fast). I
> > really can't see what could cause such a slowdown: the range over
> > which you evaluate sin should not cause denormal numbers - just to be
> > sure, could you try the same benchmark but using a simple array of
> > constant values (say numpy.ones(1000)) ? Also, you may want to check
> > what happens if you force raising errors in case of FPU exceptions
> > (numpy.seterr(raise="all")).
>
> OK, have some interesting results.  First is my array creation was not
> doing what I thought it was.  This (what I've been doing) creates an
> array of 159161 elements:
>
> numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float32)
>
> Which isn't what I was after (1000 elements ranging from 0 to 2PI).  So
> the values in that array climb up to 999.999.
>
> Running with numpy.ones() gives a much different timing (I did
> numpy.ones(159161) to keep the array lengths the same):
>
> sin float32 0.078202009201
> sin float64 0.0767619609833
> cos float32 0.0750858783722
> cos float64 0.088515996933
>
> Much better, but still a little strange, float32 should be relatively
> faster yet.  I tried with 1000 elements and got similar results.
>

Depends on the CPU, FPU and the compiler flags. The computations could very
well be done using double precision internally with conversions on
load/store.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090804/5b0abc7a/attachment-0001.html 


More information about the NumPy-Discussion mailing list