recently, I’ve discovered the power of python for numerical computing. being a slave of matlab for many years, I’ve decided to give python (and it’s numerical module numpy) a try, comparing its numerical crounching capabilities versus matlab’s.

the tests are heavily insipired by Prabhu Ramachandran. I’ve only added matlab to complete his comparisons. Here is a short description of the test, taken from here:

The example we will consider is a very simple (read, trivial) case of solving the 2D Laplace equation using an iterative finite difference scheme (four point averaging, Gauss-Seidel or Gauss-Jordan). The formal specification of the problem is as follows. We are required to solve for some unknown function u(x,y) such that

abla^2 u = 0 with a boundary condition specified. For convenience the domain of interest is considered to be a rectangle and the boundary values at the sides of this rectangle are given.

all the tests have been run on a Pentium IV Xeon 2GHz, with 1Gb of RAM.

here is the matlab script I used laplace.m (it’s a doc file: sorry for that, but I’m only allowed to upload docs and images on this blog).

matlab and numpy have pretty much the same performances. any form of optimization on python code does better than matlab. only the simple python (without numpy) is slower than matlab (note the logarithmic y scale to fit also the “slow” algorithm).

blitz is roughly twice as fast as matlab. inline, fastinline, fortran and pyrex only differ appreciably for small grids: for 500×500 grids they are around 10x faster than matlab.

here is some other digits, not included in the graphs:

numpy with psyco runs 5% faster than numpy alone;

weave and psyco (blitz, inline and fastinline) fails with following polite error: local variables of functions run by Psyco cannot be accessed in any way, sorry;

octave runs twice as slow as numpy and matlab.

pretty amazing, if you think that optimizing python, most of the time, is really trivial. moreover, python is free and easily parallelizable with MPI (I’ll show some performances in a future post).

tests have been run also on an SGI Altix with Itanium2 processors, on a single CPU. the graphs are reported in the following thumbnails.

Share this: Twitter

Facebook

Reddit

Like this: Like Loading... Related