Why is C faster than Python

Is programming in Python faster than in C, C ++, or Java? [closed]


There is a widespread belief among programmers that the more dynamic the language and the less you type it, the more productive the programmer is. Guido van Rossum wrote in 1998 about programming productivity with Python and searching the Internet. I still see people referencing this exact claim:

Syntactically, Python code looks like executable pseudo-code. Program development with Python is 5-10 times faster than with C / C ++ and 3-5 times faster than with Java. In many cases, a prototype of an application can be written in Python without writing any C / C ++ / Java code. Often times, the prototype is sufficiently functional and performing well to be delivered as a final product. This saves considerable development time. In other cases, the prototype can be translated in whole or in part in C ++ or Java - Python's object-oriented nature makes translation a straightforward process.

Was this problem scientifically assessed correctly? If not for Python, then maybe for sibling scripting languages ​​like Ruby, Perl or PHP?

I am not seeking rationalizations, analogies, or explanations as to why it might be difficult to answer unless it is the opinion of a researcher or expert who took the time to study the subject.

I initially asked this question to skeptics. SE, and someone suggested that I put them here too.






Reply:


Ousterhouts article 1 About scripting languages ​​says that the higher the programming level, the more productive the programmer is. If we accept that, like Boehm 2 says the number of lines a programmer can write in a given amount of time is constant and regardless of the language or its type (low level, system programming, scripting) the claim is easy to believe. The resulting ratio of instructions per line of source code can be an order of magnitude (or several) better for scripting languages ​​than for system programming languages.

Since scripting languages ​​rely heavily on pre-built utilities for common tasks (e.g. data structures, manipulating strings), their main use is to increase productivity while reducing speed by creating an easy-to-learn and easy-to-use utility for the Maintaining programs with efficient syntax is provided with. A scripting language is not used when the highest execution speed is required.

[1]: JK Ousterhout, Script: Higher level of programming for the 21st century , Computer (IEEE), 1998
[2]: B. Boehm, Industrial engineering for software , Prentice Hall, 1981






If you are productivity as a "Time to Write a Specific Simple Program" measure, it depends much more on the programmer's experience and quick wits than on the language you are really evaluating as a programmer rather than the language.

I believe that timed code competitions suggest that language isn't really that important for these type of tasks. There is no language that overcomes such challenges more easily than others (at least not when you consider the relative popularity of languages).

If you have the performance as a "the effectiveness of the best program" measure that is written in a particular language, then it is even less language dependent. For example, take a look at the results of the Galcon AI competition. The winner is in Lisp. The next Lisp entry, however, is number 280. What does this tell us about the suitability of the language to efficiently write great AI? Nothing in my opinion. It just tells us that "bocsimacko" developed and implemented the most effective algorithms. For recording, time wasn't an important factor in this competition - people had over two months to develop their code.

If you have the performance as a "long-term costs of maintaining a project" measure, then in my opinion you are fixated on something. Especially when you are hiring only the best people for the job and reporting costs in man-hours, not dollars. I firmly believe which languages ​​are best for this, but I have no specific pointers to link you to. Maybe someone else has links for this type of performance.





http://page.mi.fu-berlin.de/sprechelt/Biblio/jccpprtTR.pdf is one of the few studies in which, as far as I know, a direct comparison of productivity in different languages ​​was carried out. It's old but worth reading if you find the topic interesting. The comparison has a number of serious shortcomings which the article is very honest about.

The overall result is that low-level languages ​​(e.g., C, C ++) take longer to write, use much less memory, and run much faster. But with very high variability. High-quality scripting languages ​​usually require half the time to write and have less variability in approach. To an initially surprising extent, there is an obvious way of doing something in a scripting language.

Note that any KPI for Java should be taken with a large grain of salt - the paper was made in the 90s, before people got much experience with Java and before the JVM was well tweaked. Both of these factors should have a significant impact.


Generally speaking, writing a program in Python is usually faster than writing the same program in C, C ++, Java.

It will likely run slower too.

There are of course certain applications for which other languages ​​may be faster because certain tasks are supported more "natively".

While I am not aware of any studies to confirm this speed / productivity increase (as one commenter pointed out, it can be difficult to measure accurately), the expressiveness of language has been directly studied.

I think that a correlation between language expression and programming speed has some value. Just imagine a simple iteration pattern and see how a Pythonic for-loop or list comprehension can be more concise. Not only can it instantly type faster, but it also removes the concerns about individual errors, invalid indexes, and other issues that can significantly slow down the coding process.

This shows a table and an estimate of the expressivity ratios of languages. While it should be taken with a grain of salt, the footnotes mentioned in it are very worthwhile.

http://en.wikipedia.org/wiki/Comparison_of_programming_languages#Expressiveness


The last time I used Java (admittedly a while ago) I needed a screen of code to open and write to a file. Compare that to a few lines in Python or Perl and you can guess which one is faster.

Of course, all languages ​​have their own strengths and weaknesses, but for most tasks, Python is faster to write.




We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.