Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Why PyPy3 is preferred over Python3?
Next article icon

Why PyPy3 is preferred over Python3?

Last Updated : 05 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

"If you want your code to run faster, you should probably just use PyPy." 
-- Guido van Rossum (creator of Python) 
  
If you have ever coded in Python, you know how much slower it is compared to some of the other popular programming languages. In most of the online code judges, the time limit of Python is as much a 5 times more than that of C and more than twice as that of Java. 

The reason why Python usually takes 10 to 100 times more in execution is that it is a higher-level language that is dynamically typed. No matter how optimized your code is, it can't outdo C/C++ in execution time as is. However, Python is a fun language and easy language to work with, which is why programs are built much faster with it. 

To solve this problem, let's understand what Python is

Python is not a single language but rather it's a way of implementing python code. The default and the most widely used Python implementation is CPython. The flow of execution of code in CPython is :  

  1. The interpreter checks for logic and syntax errors
  2. After finding no errors, the formatted code is converted into Byte Code
  3. The Byte Code is sent to PVM(Python Virtual Machine) which converts the code into machine-readable language on which CPU performs operations.

However, CPython is not the way to implement Python. In fact, there are many other implementations: 

  • IronPython (Python running on .NET)
  • Jython (Python running on the Java Virtual Machine)
  • PyPy (A fast python implementation with a JIT compiler)
  • Stackless Python (Branch of CPython supporting micro threads)
  • MicroPython (Python running on microcontrollers)

PyPy is built using the RPython language that was co-developed with it. RPython (Restricted Python) is a subset of Python language which puts some restrictions on the Python language to make it run faster. The main reason to use it instead of CPython is its speed. Specifically, it usually runs 4.4 times faster than CPython. PyPy implements Python 2.7.13 and 3.6.9. It supports all of the core languages, passing the Python 2.7 test suite and most of the 3.6 test suite (with minor modifications) It supports most of the commonly used Python standard library modules. This means that in most cases your python code will run without any need of modifications. 

PyPy uses a technique known as meta-tracing, which transforms an interpreter into a tracing JIT (just-in-time) compiler which is a way of executing code that involves compilations during runtime. It not only runs faster but it also has better memory usage than Python. It is also highly compatible with some of the most used libraries that can be used in Python. 

Some of which are:  

  • ctypes
  • django
  • sqlalchemy
  • flask
  • twisted
  • pylons
  • divmod's nevow
  • pyglet
  • Pillow
  • lxml
  • NumPy

With so many upsides it is bound to have some negatives as well.  

Disadvantages of PyPy

PyPy cannot execute all of the Python code. Some modifications may be necessary to the Python code to execute. The external C-API have been reimplemented in PyPy but sometimes some C-abstractions leak out on CPython and are abused, perhaps even unknowingly. It requires a "Warm-up" time which causes a slight to noticeable delay in the initial execution of an application, due to the time taken to load and compile the bytecode. Smaller the execution worse will be its performance. 

 


Next Article
Why PyPy3 is preferred over Python3?

G

g0dspeed
Improve
Article Tags :
  • Python
  • Write From Home
  • Python-Miscellaneous
Practice Tags :
  • python

Similar Reads

    Why is Python So Popular?
    One question always comes into people's minds Why Python is so popular? As we know Python, the high-level, versatile programming language, has witnessed an unprecedented surge in popularity over the years. From web development to data science and artificial intelligence, Python has become the go-to
    7 min read
    Why is Numpy faster in Python?
    NumPy is a Python fundamental package used for efficient manipulations and operations on High-level mathematical functions, Multi-dimensional arrays, Linear algebra, Fourier Transformations, Random Number Capabilities, etc. It provides tools for integrating C, C++, and Fortran code in Python. NumPy
    4 min read
    Python2 vs Python3 | Syntax and performance Comparison
    Python 2.x has been the most popular version for over a decade and a half. But now more and more people are switching to Python 3.x. Python3 is a lot better than Python2 and comes with many additional features. Also, Python 2.x is becoming obsolete this year. So, it is now recommended to start using
    5 min read
    Why Python is a High Level Language
    Python is categorized as a high-level programming language because of several key characteristics and features that distinguish it from lower-level languages ​​such as assembly language or machine code. In this article, we will see why Python is a high-level language. What Does High-Level Language M
    5 min read
    History of Python
    Python is a widely used general-purpose, high-level programming language. It was initially designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed to emphasize code readability, and its syntax allows programmers to express concepts in fewer lines of
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences