Python efficiency problems?

Source: Internet
Author: User
I used java and cpp before I started python. I have long known that the interpreted script language is definitely not good. But I am confused about python, php, js, ruby, and other types of languages. Which of the following is faster? In addition, python can also be compiled into bytecode Like java. Is it faster? Can python be compiled into machine code? I used java and cpp before I started python. I have long known that the interpreted script language is definitely not good. But I am confused about python, php, js, ruby, and other types of languages. Which of the following is faster? In addition, python can also be compiled into bytecode Like java. Is it faster? Can python be compiled into machine code? Reply content: python is slow, but slow in a specific scenario. The two most important ones are: 1. The GIL lock is executed globally, so multi-core 2 cannot be used, all things are objects and internal implementations lead to slow computing. If you want to write CPU-intensive programs, we recommend that you do not use py. For IO-intensive programs, pyhton is no problem.

PS:
1. Unless the business scenario is clearly defined, it is meaningless to discuss efficiency issues. In fact, efficiency is never the top priority in most development scenarios.
2. Even if efficiency is a problem, most of the time it is not a language problem.
3. In most cases, language change is not the best choice for both "fast" and "slow" scenarios, even for language problems and comprehensive cost measurement.

Java is also slower than Python. For example, Python is much less efficient than Java in large matrix operations without NumPy, and startup is slow. In addition, with HHVM, PHP is more efficient than Python.
Therefore, we recommend that you do not use Python in scenarios with high performance requirements.

==================== Below
How high is the performance requirement? If you are using a website, at least the registered user and PV will exceed zhihu or Douban.
Yesterday I saw a website with only over one thousand registered users discussing performance issues. Let's talk about the bytecode first. Compiling python into bytecode is almost never faster. The python execution process is to first compile your code to the bytecode, and then the Virtual Machine loads the bytecode for execution. Therefore, compiling to bytecode in advance only saves a little compilation time, which can be ignored most of the time.
For official implementations, python is more efficient than ruby (php and js are not familiar with it), but the high efficiency is limited. If you really want to use python to pursue efficiency, you can try pypy. This jit-based implementation sometimes has a combination of speed and c (of course, the jit can increase the speed depends on the application scenario)
In addition, for programs whose performance bottleneck is not at the computing speed, the performance loss caused by python is still very small.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.