Is Python faster and easier C ++?

I always thought that the advantages of Python are the speed of reading and developing code, but time and memory usage are not as good as in C ++.

These statistics amazed me greatly.

What does your experience tell you about Python vs C ++ time and memory?

+63
c ++ performance python memory statistics
Apr 29 '09 at 9:51
source share
8 answers

I think you are reading these statistics incorrectly. They show that Python is about 400 times slower than C ++, and, with one exception, Python is more like memory. When it comes to source size, Python wins.

My experiences with Python show the same definite tendency that Python is in the order of 10 to 100 times slower than C ++ when doing any serious crunch. There are many reasons for this, the main of which are: a) Python is interpreted, and C ++ is compiled; b) Python has no primitives, everything, including built-in types (int, float, etc.), are objects; c) the Python list can contain objects of various types, so each entry must store additional data about its type. All this seriously complicates both the operating time and memory consumption.

This is no reason to ignore Python. Many programs do not require much time or memory, even with a 100-fold time factor. Development cost is where Python wins with a simple and concise style. This improvement in development cost often outweighs the cost of additional processor and memory resources. However, when this is not the case, C ++ wins.

+169
Apr 29 '09 at 9:55
source share

All of the slowest (> 100x) uses of Python in gunfights are scientific operations that require a high GFlop / s value. You should not use python for them. The right way to use python is to import a module that performs these calculations, and then go on a relaxing day with your family. This is the pythonic way :)

+94
Apr 29 '09 at 10:10
source share

My experience is the same as in the tests. Python can be slow and use more memory. I write a lot, much less code, and it works for the first time with much less debugging. Since it manages memory for me, I don't need to do any memory management, saving hours on chasing kernel leaks.

What is your question?

+21
Apr 29 '09 at 9:56
source share

The size of the source is not a reasonable thing to measure. For example, the following shell script:

cat foobar 

much shorter than its Python or C ++ equivalents.

+11
Apr 29 '09 at 9:58
source share

Also: Psyco vs. C ++ .

This is still a poor comparison, since no one will do numerical performance tests, which tend to focus on pure Python. It would be better to compare the performance of realistic applications or C ++ against NumPy to see if your program will be noticeably slower.

+6
Apr 29 '09 at 10:00
source share

The problem is that you have two different languages ​​that solve two different problems ... this is similar to comparing C ++ with assembler.

Python is designed to quickly develop applications and keep productivity as minimal as possible.

C ++ is not intended for rapid application development and inherits a legacy of speed from C for low-level programming.

+3
Apr 29 '09 at 10:12
source share

I think these statistics show that Python is much slower and uses more memory for these tests - are you sure you are reading them correctly?

In my experience, which is mainly related to writing programs related to the network and file system, in Python, Python does not significantly slow down. For this kind of work, its advantages outweigh its costs.

+2
Apr 29 '09 at 9:57
source share

This is the same problem with a controlled and easy to use programming language, as always - they are slow (and sometimes with memory).

These are languages ​​for management, not processing. If I had to write an application for image conversion and had to use Python, then all the processing could be written in C ++ and connected to Python via bindings, while the interface and process control would definitely be Python.

+2
Apr 29 '09 at 10:37
source share



All Articles