what's the differences python3 and pypy3

Chanyang Sim picture Chanyang Sim · Nov 26, 2019 · Viewed 8.2k times · Source

Today I knew that pypy3 is faster than python3 for input() time through any algorithm problem. Performance differences were almost as much as 12 times.

Why is there such a difference?

Answer

Saurav Rai picture Saurav Rai · Nov 27, 2019

Kindly check this, when we speak of Python programming language we often mean not just the language but also the implementation. Python is a specification for a language that can be implemented in many different ways.

The default implementation of the Python programming language is Cpython(assuming python3 you mean Cpython). As the name suggests Cpython is written in C language. Cpython compiles the python source code into intermediate bytecode, which is executed by the Cpython virtual machine.

Jython is an implementation of the Python programming language that can run on the Java platform. Jython programs use Java classes instead of Python modules. Jython compiles into Java byte code, which can then be run by Java virtual machine.

PyPy If you want your code to run faster, you should probably just use PyPy. — Guido van Rossum (creator of Python) Python is a dynamic programming language. Python is said to be slow as the default CPython implementation compiles the python source code in bytecode which is slow as compared to machine code(native code). Here PyPy comes in.

PyPy is an implementation of the Python programming language written in Python. The Interpreter is written in RPython (a subset of Python). PyPy uses Just In Time (JIT) compilation. In simple terms, JIT uses compilation methods to make the interpreter system more efficient and fast. So basically JIT makes it possible to compile the source code into native machine code which makes it very fast. PyPy also comes with default support for stackless mode, providing micro-threads for massive concurrency. Python is said to be approximately 7.5 times faster than Cpython.

Hope this will help you.