There is a total lack of vectorization in your code, so you are right about the lack of vectorization.

What happens is that you see the result of the Matlab JIT compiler speeding up the loop.

With a vectorized array expression, there will hardly be any difference.

Sturla


Den 19.07.2011 11:05, skrev Carlos Becker:
Hi, I started with numpy a few days ago. I was timing some array operations and found that numpy takes 3 or 4 times longer than Matlab on a simple array-minus-scalar operation. This looks as if there is a lack of vectorization, even though this is just a guess. I hope this is not reposting. I tried searching the mailing list database but did not find anything related specifically to a problem like this one.

Here there is the python test code:

--------------------------------------------

from datetime import datetime

import numpy as np

def test():

m = np.ones([2000,2000],float)

N = 100

t1 = datetime.now()

for x in range(N):

k = m - 0.5

t2 = datetime.now()

print (t2 - t1).total_seconds() / N

--------------------------------------------


And matlab:


--------------------------------------------

m = rand(2000,2000);


N = 100;

tic;

for I=1:N

    k = m - 0.5;

end

toc / N

--------------------------------------------


I have the impression that the speed boost with Matlab is not related to matlab optimizations, since singe-runs also render similar timings.

I tried compiling ATLAS for SSE2 and didn't observe any difference. Any clues?


Thanks,

Carlos



_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to