What makes Python a slow language ? - GeeksforGeeks (2023)

Improve Article

Save Article

Like Article

(Video) 5 Reasons to Learn Python in 2021 | Ishan Sharma | GeeksforGeeks

  • Difficulty Level :Medium
  • Last Updated :22 Jul, 2021

Improve Article

Save Article

Like Article

(Video) Python Is Slow?? #python #coding #programming

Python is a high-level language (than C or C++) thus Python itself manages details of a program like memory allocation, memory deallocation, pointers, etc. This makes writing codes in Python easier for programmers. Python code is first compiled into python Byte Code. The Byte Code interpreter conversion happens internally and most of it is hidden from the developer. Byte code is platform-independent and lower-level programming. Compilation of byte code is to ramp up the execution of source code. The source code compiled to byte code is then executed in Python’s virtual machine one by one, to carry out the operations. The virtual machine is an internal component of Python.

(Video) Coding Motivation | Coding Journey | Hackerrank | GeeksForGeeks | Leetcode

Internally Python code is interpreted during run time rather than being compiled to native code hence it is a bit slower.

Running of Python script v/s running of C/C++ code:

Python: First it is compiled into Byte Code. This Byte Code is then interpreted and executed by the PVM (Python Virtual Machine).

What makes Python a slow language ? - GeeksforGeeks (1)

C/C++: The source code is compiled into Binary Code which can be directly executed by the CPU making them more efficient.

(Video) Things To Know Before Start Programming | GeeksforGeeks

What makes Python a slow language ? - GeeksforGeeks (2)

Major Reasons for Python being slow:

  • Being Interpreted: Unlike native languages like C/C++, Python code gets interpreted at runtime instead of being compiled to native code at compile time. Python is an interpreted language, which means that the Python code we write must go through many, many stages of abstraction before it can become executable machine code.
  • Just In Time (JIT) Compiler: Other interpreted languages like Java/.NET byte code run faster than Python’s byte code because their standard distribution includes a JIT compiler that compiles byte code into native code at run time. Python does not have a JIT compiler because the dynamic nature of Python makes it difficult to write one. It is impossible to say what type of parameters will be passed to a function, which makes optimization a bit harder.
  • Global Interpreter Lock (GIL): It prevents multi-threading by mandating the interpreter to execute only a single thread within a single process (i.e. an instance of Python interpreter) at a time.

My Personal Notesarrow_drop_up

Like Article

(Video) Introduction to Python | Sandeep Jain | GeeksforGeeks

Save Article

Videos

1. Top 7 Programming Languages to Learn in 2021 | Ishan Sharma | GeeksforGeeks
(GeeksforGeeks)
2. 5 Coding Myths that You Must Know! | GeeksforGeeks
(GeeksforGeeks)
3. Interesting facts about strings in Python | GeeksforGeeks
(GeeksforGeeks)
4. Peak Element | GeeksForGeeks | Placement & Interview | Easy | C++ Implementation
(CodeMinati (Interview Code))
5. Python for Beginners #3 : Language Processors
(Techno Puzzle)
6. Do THIS To Stay Consistent In CODING! Ft. Prakash Sakari, Mentor-GeeksforGeeks
(GeeksforGeeks)

References

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated: 10/20/2023

Views: 5649

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.