[Tutor] BLAS Implementation on Python

Stefan Behnel stefan_ml at behnel.de
Tue Mar 8 11:11:09 CET 2011

Alan Gauld, 08.03.2011 09:51:
> "Knacktus" wrote
>> He doesn't have to write it, as it is very obvious, that no Python code
>> on earth (even written by Guido himself ;-)) stands a chance compared to
>> Fortran or C. Look at this:
> There is one big proviso. The C or Fortran needs to be well written
> in the first place. It's quite possible to write code in Python that
> outperforms badly written C. And it is quite easy to write bad C!

It's seriously hard to write computational Python code that is faster than 
C code, though. It shifts a bit if you can take advantage of Python's 
dynamic container types, especially dicts, but that's rarely the case for 
mathematic computation code, which would usually deploy NumPy etc. in 
Python. Writing that in pure Python is bound to be incredibly slow, and 
likely still several hundred times slower than even a simple approach in C. 
There's a reason people use NumPy, C, Fortran and Cython for these things.

Remember that the OP's topic was a BLAS implementation. The BLAS libraries 
are incredibly well optimised for all sorts of platforms, including GPUs. 
They are building blocks that C programmers can basically just plug into 
their code to run hugely fast computations. There is no way Python code 
will ever be able to get any close to that.


More information about the Tutor mailing list