4 Feb 2004 arauzo   » (Journeyer)

Efficiency of Python vs. C++

Obviously I am not going to give the final answer to such a question like which one is faster. It depends on what you are programming and their requisites, and if you need maximun speed you may need to use C++, C or even assembler. But I want to share with you my little experiment.

I wrote a small C++ library for handling tables of data of diverse types. I did it aiming to clarity and usability, and so I used many inheritance and virtual methods. I recognize efficiency was not my priority.

Then I needed to convert ascii files of tabbed data with different formats to mine. I needed to write too much code in C++ (and I wanted to learn python I must confess) so I wrote a python script to do that (with a Gtk interface thanks to lgs).

Fascinated by the simplicity of Python code (as I told you on 29th) I decided to wrote in Python a feature selection algorithm I had previously wrote in C++. Today I have decided to test their speed and these are the results:

  1. Python: 29 minutes
  2. C++: 33 minutes

Well, it is not a very scientific experiment, and I cheated C++ because it is loading the table 32 times (it takes just a few seconds). But, hey! I expected C++ to win by large.

Good (coding is simpler now) and bad news (it took long time to wrote C++ lib) for me. But definitely a BIG surprise!

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!