speed of python vs matlab.

Robert Kern robert.kern at gmail.com
Thu Dec 14 11:22:59 EST 2006


Chao wrote:
> While trying this another question comes up,
> psyco seems to be able to optimize built-in functions & user's code, if
> I call a function from an external library, it seems doesn't help.
> A simple thing is I placed a = numpy.sin(a) in the loop rather than a =
> a+1, in this case,
> psyco doesn't have any improvement(or very little). if I put a =
> math.sin(a) which is from an built-in function, it can achieve a
> improvement around 3~4.   Could the reason be that numpy.sin is
> actually calling a C library ?

The reason for the difference is that psyco recognizes math.sin() and replaces
it with equivalent machine code to call the standard C library function sin().
It does not recognize numpy.sin(), and it is implemented in C, not Python, so it
does not do optimization.

> Actually Python does show comparable/better performance than other
> scripting languages. but I'm just surprised that matlab does a great
> job compared to python/perl, since matlab is also a interpreted
> language, I'm expecting it has silimar performance with python.

Matlab uses a JIT compiler along the lines of psyco for simple operations like
the one you are doing.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list