PyPy – Introduction
What is PyPy :
PyPy is a very compliant Python interpreter, almost a drop-in replacement for CPython 2.7.10 and 3.3.5. It’s fast due to its integrated tracing JIT compiler.
On average, PyPy is 4.2 times faster than CPython. Sometimes Cpython may get TLE while execution but the same code may run fine with PyPy.In general if c++ takes 1 second to execute a file , if we execute same file with python it will take upto 5 seconds.
Advantages and distinct Features
-
Speed: thanks to its Just-in-Time compiler, Python programs often run faster on PyPy.
-
Memory usage: memory-hungry Python programs (several hundreds of MBs or more) might end up taking less space than they do in CPython.
-
Compatibility: PyPy is highly compatible with existing python code. It supports cffi, cppyy, and can run popular python libraries like twisted, and django. It can also run NumPy, Scikit-learn and more via a c-extension compatibility layer.
-
Stackless: It comes by default with support for stackless mode, providing micro-threads for massive concurrency.
Example #1:
Output :
In the loop
Out of loop
Time: 0.91280354000628
Output :
In the loop
Out of loop
Time: 0.02118576504290104
Login/Signup to comment