speed of python vs matlab.

Jonathan Curran jonc at icicled.net
Thu Dec 14 00:19:34 EST 2006


On Wednesday 13 December 2006 18:07, Chao wrote:
> 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.

[icicled at A3200 ~]$ time python foo # where foo contained your exact code

real    0m0.469s
user    0m0.443s
sys     0m0.017s

4.5 seconds? ouch. I've got somewhere near 1 second. Something sounds a little 
fishy b/c my machine is an AMD 3200+ (2.2GHz) w/ 1GB RAM. Yours is a lot 
faster in terms of clock speed.

Anyway, do take a look at some of the available python compilers. They should 
help considerably.

- Jonathan



More information about the Python-list mailing list