[Numpy-discussion] Matlab/Numeric/numarray benchmarks

Bruce Southey southey at uiuc.edu
Thu Jan 6 06:31:34 CST 2005

While on the subject on benchmarks, I thought I would point out an really   
excellent book by Hans Petter Langtangen's book:    
'Python Scripting for computational science' (Springer, 2004:  
http://www.springeronline.com/sgw/cda/frontpage/0,0,4-0-22-17627636-0,0.html ).    
The book web site is http://folk.uio.no/hpl/scripting/    
that also has the scripts.    
There is considerable detailed material on using Numeric and numarray as well  
as using Python callbacks from C/C++ and Fortran. Also addresses GUI 
programming and other topics in Python including regular expressions.  
One of the really great things about this book is the discussion on how to   
improve code with reference to a single example called gridloop. Gridloop just   
evaluates a function (the actual function used was 'sin(x,y) + 8*x') over a  
rectangular grid and stores the results in an array. There are well over 25  
versions from using straight C, Fortran and C++ to using Python and Numerical 
These benchmarks are on different ways to implement this gridloop function  
in Fortran, C/C++, numarray, Numeric and Python callbacks from C/C++ and   
Fortran. In the vectorized form relative to the F77 version, numarray (v0.9)  
was 2.7 times slower and Numeric (v23) was 3.0 times slower.    
Another items that appeared was that since the sin function is scalar, there   
was a huge difference in the Python implementation between using math.sin (140   
times slower than F77),  Numeric.sin (230 times slower than F77)and   
numarray.sin (350 times slower than F77). Perhaps, this suggests that namespace   
should be checked for scalar arguments before using vectorized versions.   
Bruce Southey   

More information about the Numpy-discussion mailing list