Python Only 30% Slower than C In Certain Cases

Kamilche klachemin at home.com
Wed Jun 2 02:22:06 EDT 2004


I have a very unusual application written in C, one which uses
dictionaries for all data storage, and a unique file structure. After
staring at a current task for a bit, I decided I REALLY wanted to pass
the arguments as dictionaries, as well. I knew Python, and realized
this application was screaming to be written in Python.

It's a non trivial application - it emulates Python inheritance by
loading text files at runtime. It uses a single generic object, and
several lookup tables in memory. I finally got it to the point where
it can create objects, and store them in the table, so I performed my
first timing test.

I was VERY surprised to discover that the C program created 40,000
objects per second, and the Python version created 28,000 objects per
second! Plus, the memory footprint was less. This test was done with
the debug version of the C program. The release version showed it was
about 12x faster than Python, with a smaller memory footprint.

Still, that's more impressive than I had thought. I recreated the
wheel when making this app in C, setting up the memory management,
hash tables, and all... the design is nice and the class structures
are easily modified outside the program, and I was willing to trade
speed for this flexibility. How far am I willing to trade? Ooh, this
is tempting, to code the application in Python, instead of using it as
a prototyping tool

I'll just play with it a bit longer, code up the rest of the
functionality and run some more timings. I must say, development speed
with Python blows C out of the water, by MORE than a factor of 15.

--Kamilche



More information about the Python-list mailing list