Python is slow?

sturlamolden sturlamolden at yahoo.no
Fri Sep 26 06:08:52 EDT 2008


On Sep 26, 5:45 am, "David Cournapeau" <courn... at gmail.com> wrote:

> I am fairly experienced in matlab (have been using it extensively for
> 5 years in academical context), and now with numpy, and generally,
> they are comparable speed-wise. Matlab has some niceties which makes
> it faster in some simple cases (JIT for loops, function calls faster,
> sometimes COW semantics means it faster),

I've used Matlab for 10 years.

Matlab has a horrible pass-by-value semantics, which means that arrays
are copied in and copied out form function calls. Yes there is a copy-
on-write optimization. But unless you are not careful, it will kill
performance and make memory usage skyrocket. Also, slicing creates a
new array, whereas in numpy slicing gives you a view of an existing
array. This generally makes Matlab slow, and it wastes terrible
amounts of memory.

For example I once tested D4 wavelet transforms on a 64 MB array of
doubles (i.e. length 2**23). Matlab R14 Service Pack 2 did this in 27
seconds, whereas Python 2.4 with NumPy 1.0 one required 3.4 seconds.
That is an order of magnitude speed difference in favour of Python.

Matlab also has a strange habit of fragmenting the heap. This can be
so bad that you have to stop the script, run a special function called
pack() do defragement, and restart. I've never seen that with Python.

I more or less stopped using Matlab 3 years ago, and I have not
renewed my subscription for maintenance of my personal Matlab license
since. Matlab is a nice tool, but I have grown past it.

Matlab's strongest side is data visualization though. Although we have
matplotlib, mayavi and possibility of interfacing with gnuplot, it's
not anywhere near the capabilities of Matlab.









More information about the Python-list mailing list