Python Only 30% Slower than C In Certain Cases

K

Kamilche

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
 
H

Harald Massa

the debug version of the C program. The release version showed it was
about 12x faster than Python, with a smaller memory footprint.

Can you please check out a test run with psyco?

psyco.sourceforge.net


at the beginning of your programm

import psyco
psyco.full()

Would be interested in the speed differences...
 
G

gongoozler

There was a recent artical on OSNews (link below) that compared a
number of languages, including C, C#, C++ and Python. Although the
Python version of the benchmarks was ultimatlely blown away by the C*
flavours it did perform amazingly well in some parts of the benchmark,
I/O for example. Psyco proved to be a real benefit for such a small
change.

I agree that the ease that you can produce a working prototype/proof
of concept is impressive. It's always worth evaluating your code, look
at the performance hot-spots before throwing it away in favour of
something 'quicker'.

http://osnews.com/story.php?news_id=5602&page=1

Regards,

MarcH
 
M

Michael Geary

Kamilche said:
...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.

So, your message title is wrong. It should read:

"Python Only 12 times slower than C in certain cases"

;-)

The point is that nobody would ever do a performance comparison using
*unoptimized* C code.

I'm with you on the development speed of Python, though. I'd rather use
Python or Ruby any day instead of C/C++.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,328
Latest member
66Teonna9

Latest Threads

Top