from:52097060
Https://stackoverflow.com/questions/17130975/python-vs-cpython
Introduction to the Python interpreter
An interpreter is a program that allows other programs to run, which is the software logic layer between the code and the machine's computer hardware, and the Python interpreter is a set of programs that allow Python programs to execute on the machine.
The Python interpreter performs two steps when we execute a written Python code
1. Compile the original code into byte code
The compiled bytecode is a Python-specific form of representation that is not a binary machine code that needs to be further compiled to be executed by the machine, which is why Python code cannot run as fast as C + +. If the Python process has write permissions on the machine, it will save the program's bytecode as a file with a. pyc extension, and if Python cannot write bytecode on the machine, the bytecode will be generated in memory and discarded automatically at the end of the program. When building a program, it is best to give Python permission to write on the computer so that, as long as the source code does not change, the resulting. pyc file can be reused to improve execution efficiency.
2. Forward the compiled bytecode to the Python virtual machine (PVM) for execution
PVM is the short name of Python Virtual machine, which is the python running engine, is a part of the Python system, it is a large loop that iterates through the bytecode instruction, and completes the operation one by one.
Several implementation versions of the Python interpreter
There are three main implementations of the Python interpreter, the CPython, Jython, and IronPython implementations in three ways.
1, CPython
CPython are standard implementations, others have specific goals.
CPython is written in C, which is the Python interpreter for most Linux and Mac OS x machines, and is the fastest, most complete, and most robust of all python interpreters.
2. Jython
Jython is an alternative implementation of the Python language, designed to integrate with the Java programming language, which includes Java classes that compile Python source code, form Java bytecode, and map the resulting bytecode to the Java Virtual Machine (JVM). Because Jython is slower and less robust than cpython, it is often seen as an interesting tool for Java developers looking for the scripting language of the Java code front-end.
3, IronPython
The purpose of the IronPython design is to enable the Python program to integrate with the. NET Framework on the Windows platform and the applications that are written as open source mono for Linux.
Psyco Real-time compiler
The Psyco system is not another way to implement Python, but rather an extension of the Python bytecode execution module, which allows the program to run faster. It is a PVM enhancement tool that collects and uses information that, when the program is running, can convert some of the program's bytecode into the underlying real binary machine code for faster execution. During the development process, the Psyco does not require code modification or a separate compilation step to complete the conversion.
In a nutshell, when the program is running, Psyco collects class information about the objects that are being passed, which can be used to clip the type of the object to produce efficient machine code. Once the machine code is generated, it replaces the corresponding original bytecode, thus speeding up the overall execution speed of the program. Some Python code optimized by Psyco can execute as fast as the compiled C code.
Because byte-code conversions occur at the same time as the program runs, Pysco is often seen as an instant compiler (JIT). In fact, Psyco is a proprietary JIT compiler: it generates machine code that streamlines the data type to the type that your program actually uses.
Psyco is implemented using pure Python's algorithmic code. This is especially important when you use Psyco to optimize the part of the code that often needs to be migrated to C, so the migration is not necessary.
Python run mechanism (GO)