[Numpy-discussion] numpy speed question

Jean-Luc Menut jeanluc.menut at free.fr
Thu Nov 25 05:13:49 EST 2010


Hello all,

I have a little question about the speed of numpy vs IDL 7.0. I did a 
very simple little check by computing just a cosine in a loop. I was 
quite surprised to see an order of magnitude of difference between numpy 
and IDL, I would have thought that for such a basic function, the speed 
would be approximatively the same.

I suppose that some of the difference may come from  the default data 
type of 64bits in numpy and 32 bits in IDL. Is there a way to change the 
numpy default data type (without recompiling) ?

And I'm not an expert at all, maybe there is a better explanation, like 
a better use of the several CPU core by IDL ?

I'm working with windows 7 64 bits on a core i7.

any hint is welcome.
Thanks.

Here the IDL code :
Julian1 = SYSTIME( /JULIAN , /UTC )
for j=0,9999 do begin
   for i=0,999 do begin
     a=cos(2*!pi*i/100.)
   endfor
endfor
Julian2 = SYSTIME( /JULIAN , /UTC )
print, (Julian2-Julian1)*86400.0
print,cpt
end

result:
% Compiled module: $MAIN$.
        2.9999837


The python code:
from numpy import *
from time import time
time1 = time()
for j in range(10000):
     for i in range(1000):
         a=cos(2*pi*i/100.)
time2 = time()
print time2-time1

result:
In [2]: run python_test_speed.py
24.1809999943




More information about the NumPy-Discussion mailing list