Ousterhout's article1 about scripting languages suggests that the higher level the programming takes place, the more productive the programmer is. If we take that, as Boehm says2, the number of lines a programmer can write in a given time is constant and not dependent on the language or its type (low level, system programming, scripting), one can easily believe the claim. The resulting instructions-per-source-code-line -ratio can be an order of magnitude (or several) better with scripting languages than with system programming languages.
As scripting languages heavily rely on ready-made utilities for common tasks (e.g. data structures, string manipulation), their main use usually is to enhance productivity with the cost of slower running speed by providing a syntax that's easy to learn and efficient to upkeep programs with. One doesn't resort to a scripting language when top execution speed is needed.
[1]: J. K. Ousterhout, Scripting: Higher Level Programming for the 21 Century, Computer (IEEE), 1998
[2]: B. Boehm, Software Engineering Economics, Prentice Hall, 1981
Ousterhout's article1 about scripting languages suggests that the higher level the programming takes place, the more productive the programmer is. If we take that, as Boehm says2, the number of lines a programmer can write in a given time is constant and not dependent on the language or its type (low level, system programming, scripting), one can easily believe the claim. The resulting instructions-per-source-code-line -ratio can be an order of magnitude (or several) better with scripting languages than with system programming languages.
As scripting languages heavily rely on ready-made utilities for common tasks (e.g. data structures, string manipulation), their main use usually is to enhance productivity with the cost of slower running speed by providing a syntax that's easy to learn and efficient to upkeep programs with. One doesn't resort to a scripting language when top execution speed is needed.
[1]: J. K. Ousterhout, Scripting: Higher Level Programming for the 21 Century, Computer (IEEE), 1998
[2]: B. Boehm, Software Engineering Economics, Prentice Hall, 1981
If you measure productivity as "time to write a specific simple program" then it depends so much more on programmer experience and quick mind than the language that you are really evaluating the programmer, not the language.
I believe timed code contests indicate that the language doesn't really matter for those kinds of tasks. There is no one language that wins such challenges easier than others (at least not if you allow for the relative popularity of languages).
If you measure performance as "the effectiveness of the best program" written in a given language, then it's even less language-dependent. See for example the results of the Galcon AI contest. The winner is written in Lisp. The next Lisp entry, however, is ranked #280. What does this tell us about the language's suitability for writing great AI efficiently? In my opinion, nothing. It just tells us that "bocsimacko" came up with and implemented the most effective algorithms. For the record, time was not a major factor in this contest - people had more than two months to develop their code.
Lastly, if you measure performance as "long-term cost of maintaining a project" then I think you're onto something. Especially if you hire only the best people for the job, and count cost in man-hours rather than dollars. I have a strong opinion on which languages are best for this, but having no hard evidence to link you to I'll leave this opinion out. Perhaps someone else has links for this type of performance.
Videos
I saw a video on YouTube about how much slower python could be compared to C++ in some instances, so I tried to test it myself, a simple program that counts from 0 to 1000,000,000 and displays the 1000,000,000 afterwards. The exception in my case was that I also tested this for C and Java, and found that as expected, C was faster than C++(not by much though) and python(by leaps and bounds), but to my surprise, Java was the fastest, even faster than C, how could this be?
Execution Times:
C - 2.815s C++ - 2.837s Python - 2m 1.451s Java - 0.861s
Don't conflate Language and Run-Time.
Python (the language) has many run-time implementations.
CPython is usually interpreted, and will be slower than native-code C#. It might be slower than Java, depending on the Java JIT compiler.
JYthon is interpreted in the JVM and has the same performance profile as Java.
IronPython relies on the same .NET libraries and IL as C#, so the performance difference will be relatively small.
Python can be translated to native code via PyREX, PyToC, and others. In this case, it will generally perform as well as C++. You can -- to an extent -- further optimize C++ and perhaps squeeze out a little bit better performance than unoptimized output from PyREX.
For more information, see http://arcriley.blogspot.com/2009/03/so-long-pyrex.html
Note that Python (the language) is not slow. Some Python run-times (CPython, for example) will be slower than native-code C++.
It is not really correct to ask why Python is slower than Java/C#. How fast is Java? Well, naive interpreters are around ten times slower than optimised compilers. I believe there is a Java bytcode interpreter written in JavaScript - that probably isn't very fast. So, the intended question appears to be "Why is the CPython language system slower than the equivalent Sun, IBM and Oracle JRE and Microsoft .NET runtime?"
I believe the correct answer is non-technical. The fastest Java and .NET runtime are faster because they have large full time technical teams developing them in performance-competitive environment.
Dynamic language systems are easy to implement. Any idiot can do it. I have. Static language systems are more complex to design and implement. A simple static system will tend to run much faster than the equivalent just-working dynamic equivalent. However, it is possible for highly optimised dynamic systems to run almost as fast. I understand some Smalltalk implementation were quite good. An often quoted example of a developed dynamic system is the MIT Lisp Machine.
In addition if the real grunt is being done by library code, then the language system may not matter. Alternatively, the language may encourage (or give time(!)) to develop more efficient algorithms which can easily wipe out constant factor performance differences.
Java is said to be much faster than python but there are different ways to run these languages (e.g. pypy for python, maybe dalvik for java). Is there any way python could be made faster than java?
Hey y'all, I'll be needing to choose either one of Java, python, c++ or web programming for my second semester in electronics and communications but i have no idea where to start from
I've learnt all the basics of c programming in my first semester and i have to choose between the above mentioned for the second semester and it's really rattling my brain
Which of them would be better for a beginner to programming language and which would be most helpful in the future, if you'd have to say?
Thanks in advance!
Java is faster than Python. Easily.
Python is favorable for many things; speed isn't necessarily one of them.
References
- python.org/Language Comparisons
- C++ vs Java vs Python vs Ruby : a first impression
- A subjective analysis of two high-level, object-oriented languages: Comparing Python to Java
If you ignore the characteristics of both languages, how do you define "SPEED"? Which features should be in your benchmark and which do you want to omit?
For example:
- Does it count when Java executes an empty loop faster than Python?
- Or is Python faster when it notices that the loop body is empty, the loop header has no side effects and it optimizes the whole loop away?
- Or is that "a language characteristic"?
- Do you want to know how many bytecodes each language can execute per second?
- Which ones? Only the fast ones or all of them?
- How do you count the Java VM JIT compiler which turns bytecode into CPU-specific assembler code at runtime?
- Do you include code compilation times (which are extra in Java but always included in Python)?
Conclusion: Your question has no answer because it isn't defined what you want. Even if you made it more clear, the question will probably become academic since you will measure something that doesn't count in real life. For all of my projects, both Java and Python have always been fast enough. Of course, I would prefer one language over the other for a specific problem in a certain context.