Beginner Python, previously engaged in Java and CPP. It has long been known that the explanatory scripting language must be unpleasant. But wondering what kind of language, such as Python and Php,js,ruby, is more efficient in terms of running efficiency alone? In addition, Python can be compiled into bytecode like Java, is not the speed is much improved? Can python be compiled into machine code?
Reply content:
Python is slow, but slow in a particular scenario, two of the most important: 1, global execution lock Gil so cannot use multicore 2, everything is object and internal implementations cause slow computation. If you want to write CPU-intensive programs, it is recommended not to use PY, if it is an IO-intensive program, Pyhton no problem.
Ps:
1, unless the business scenario is clear, it doesn't make sense to discuss efficiency issues, in fact, most of the time, efficiency is never the first problem.
2, even if efficiency is a problem, it is most of the time not a language problem
3, even if it is a language problem, comprehensive measurement of costs and other factors, most of the time to change the language is not the best choice of "fast" and "slow" is to see the scene
Java is also slower than python, such as large matrix operation is not NumPy efficient, startup is slow and so Python efficiency is much worse than Java, and after the HHVM, PHP efficiency is higher than python.
It is recommended that you do not use Python for high performance requirements.
=============== below the Groove ==================
Performance requirements are more well paid high? If you are doing a website, at least registered users and PV to more than know or watercress.
Yesterday saw a registered user only more than 1000 of the website is discussing performance issues. Let's talk about bytecode. Python compiles into bytecode almost never gets faster. The python execution process is to compile your code into bytecode first, and then the virtual machine loads the bytecode execution. So compiling to bytecode in advance can only save a bit of compilation time, and most of the time it is negligible.
As far as official implementations are concerned, Python is more efficient than Ruby (PHP and JS do not understand), but it is limited in height. If you really want to use Python to pursue efficiency, you can try the pypy, the implementation of the JIT with a certain time speed and C have a spell (of course, JIT can speed up how much depends on the application scenario)
In addition, Python's performance penalty is small and small for programs that do not have a performance bottleneck in their computing speed.