473,473 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Python Only 30% Slower than C In Certain Cases

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
Jul 18 '05 #1
4 1236
>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...
Jul 18 '05 #2
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
Jul 18 '05 #3
Harald Massa <cp*********@spamgourmet.com> wrote in message news:<Xn**********************************@62.153. 159.134>...
Can you please check out a test run with psyco?


Hm, that bumped it up to 34,000, which is about a 21% improvement.
Jul 18 '05 #4
Kamilche wrote:
...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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
7
by: stormslayer | last post by:
Folks: I've been considering a shift to python. I currently use c++builder (borland) or perl. I do computational models / statistics programming, and was interested in python b/c it a. has...
7
by: ccdetail | last post by:
http://www.journyx.com/pdf/PythonAtAGlance.pdf the above paper is a response to some of our prospects complaints they were asking us why we use python thought you guys might be interested ...
47
by: Michael Scarlett | last post by:
There is an amazing article by paul graham about python, and an even better discussion about it on slashdot. The reason I point this out, is the more I read both articles, the more I realised how...
52
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
24
by: Richard Blackwood | last post by:
Is it possible to prototype an operating system in Python? If so, what would such a task entail? (i.e. How would one write a boot-loader in Python?) - Richard B.
31
by: Mark Dufour | last post by:
Hi all, I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an optimizing Python-to-C++ compiler. Shed Skin allows for translation of pure (unmodified), implicitly statically typed...
16
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.