[Numpy-discussion] strange sin/cos performance
Bruce Southey
bsouthey@gmail....
Wed Aug 5 04:20:12 CDT 2009
On Tue, Aug 4, 2009 at 9:42 PM, Charles R
Harris<charlesr.harris@gmail.com> wrote:
>
>
> On Tue, Aug 4, 2009 at 7:18 PM, Jochen <cycomanic@gmail.com> wrote:
>>
>> Hi all,
>> I see something similar on my system.
>> OK I've just done a test. System is Ubuntu 9.04 AMD64
>> there seems to be a regression for float32 with high values:
>>
>> In [47]: a=np.random.rand(10000).astype(np.float32)
>>
>> In [48]: b=np.random.rand(10000).astype(np.float64)
>>
>> In [49]: c=1000*np.random.rand(10000).astype(np.float32)
>>
>> In [50]: d=1000*np.random.rand(1000).astype(np.float64)
>>
>> In [51]: %timeit -n 10 np.sin(a)
>> 10 loops, best of 3: 251 µs per loop
>>
>> In [52]: %timeit -n 10 np.sin(b)
>> 10 loops, best of 3: 395 µs per loop
>>
>> In [53]: %timeit -n 10 np.sin(c)
>> 10 loops, best of 3: 5.65 ms per loop
>>
>> In [54]: %timeit -n 10 np.sin(d)
>> 10 loops, best of 3: 87.7 µs per loop
>>
>> In [55]: %timeit -n 10 np.sin(c.astype(np.float64)).astype(np.float32)
>> 10 loops, best of 3: 891 µs per loop
>
> Is anyone with this problem *not* running ubuntu?
>
Yes but I do not consider a 'problem'.
While not an expert in this, this looks to be related to 64 bit OSes
running on 64bit processors, probably compiler related, and probably a
feature of Python. As I have tried to show, I do not think that these
timing are being performed correctly because when you pass a single
argument to Python at the command prompt you get the comparable
timings.
The difference in timing occurs when you pass two arguments to Python.
I do not use IPython so I am only guessing but you need to do the
timing at the same time. Probably something like:
%timeit -n 10 np.sin(numpy.arange(0.0, 1000, (2 * 3.14159) / 1000,
dtype=np.float32))
Note there is a most likely a penalty involved in type conversion that
needs to be addressed in any timings.
Bruce
More information about the NumPy-Discussion
mailing list