Extension Modules in Python

No comments

Python is on the order of between 10 and 100 times slower than C, C++, FORTRAN when doing any serious number crunching.

There are many reasons for this:

  • Python is interpreted
  • Python has no primitives, everything including the builtin types are objects
  • Python list can hold objects of different type, so each entry has to store additional data about its type.

But these are no reason to ignore Python though. A lot of software doesn't require much time or memory even with the 100 time slowness factor. Development cost is where Python wins with the simple and concise style. This improvement on development cost often outweighs the cost of additional cpu and memory resources.

It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that cant be done directly in python:

  • They can implement new built-in object types
  • They can call C library functions and system calls
  • This improves python's computational speed many folds.
My extension modules code repository on git.

No comments :