speed of python vs matlab.

Chao devincyu at gmail.com
Wed Dec 13 19:07:20 EST 2006


I've been trying to develop some numerical codes with python, however
got disappointed.

A very simple test,

a = 1.0

for i in range(1000):
     for j in range(1000):
           a = a+1

unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)

for matlab, the same operation took 0.1 seconds,

I use numpy & scipy, they solve the problem most of the times, but
there are cases you can't avoid loops by vectors. I appreciate the
elegancy of python so much, but I guess I have to gave it up in these
numerical codes.(image processing algorithms),  for application
dev/scripting, it's still my first choice.

A good news is that the same code takes ruby 9.8 seconds.




More information about the Python-list mailing list