[Numpy-discussion] strange sin/cos performance

Bruce Southey bsouthey@gmail....
Mon Aug 3 13:19:01 CDT 2009


On 08/03/2009 12:51 PM, Andrew Friedley wrote:
> Charles R Harris wrote:
>    
>> What compiler versions are folks using? In the slow cases, what is the
>> timing for converting to double, computing the sin, then casting back to
>> single?
>>      
>
> I did this, is this the right way to do that?
>
> t = timeit.Timer("numpy.sin(a.astype(numpy.float64)).astype(numpy.float32)",
>                   "import numpy\n"
>                   "a = numpy.arange(0.0, 1000, (2 * 3.14159) / 1000,
> dtype=numpy.float64)")
> print "sin converted float 32/64", min(t.repeat(3, 10))
>
> Timings on my opteron system (2-socket 2-core 2GHz):
>
> sin float32 1.13407707214
> sin float64 0.133460998535
> sin converted float 32/64 0.18202996254
>
> Not too surprising I guess.
>
> gcc --version shows:
>
> gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
>
> My compile flags for my Python 2.6.1/NumPy 1.3.0 builds:
>
> -Os -fomit-frame-pointer -pipe -s -march=k8 -m64
>
> Andrew
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>    

Hi,
Can you try these from the command line:
python -m timeit -n 100 -s "import numpy as np; a = np.arange(0.0, 1000, 
(2*3.14159) / 1000, dtype=np.float32)"
python -m timeit -n 100 -s "import numpy as np; a = np.arange(0.0, 1000, 
(2*3.14159) / 1000, dtype=np.float32); b=np.sin(a)"
python -m timeit -n 100 -s "import numpy as np; a = np.arange(0.0, 1000, 
(2*3.14159) / 1000, dtype=np.float32); np.sin(a)"
python -m timeit -n 100 -s "import numpy as np; a = np.arange(0.0, 1000, 
(2*3.14159) / 1000, dtype=np.float32)" "np.sin(a)"

The first should be similar for different dtypes because it is just 
array creation. The second extends that by storing the sin into another 
array. I am not sure how to interpret the third but in the Python prompt 
it would print it to screen. The last causes Python to handle two 
arguments which is slow using float32 but not for float64 and float128 
suggesting compiler issue such as not using SSE or similar.


Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090803/00db6c2c/attachment-0001.html 


More information about the NumPy-Discussion mailing list