fbpx

What makes Python such a slow programming language?

分享到 facebook
分享
分享到 linkedin
分享
分享到 twitter
鸣叫
How To Get Your First Coding Job

Python is a high-level language (higher than C or C++), therefore it handles program minutiae like memory allocation, memory deallocation, pointers, and so on. This makes it easy for programmers to write Python programs. Python code is converted into python Byte Code initially. Internally, the Byte Code interpreter conversion occurs, and the majority of it is hidden from the developer. Byte code is a lower-level programming language that is platform-independent. The purpose of byte code compilation is to speed up the execution of source code. To carry out the operations, the source code is compiled to byte code and then run one by one in Python’s virtual machine. Python’s virtual machine is a built-in feature.

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

Python script execution vs. C/C++ code execution:

Python: It is first converted to Byte Code. The PVM (Python Virtual Machine) then interprets and executes this Byte Code.

C/C++: The code is compiled to Binary Code, which may be directly performed by the CPU, resulting in increased efficiency.

The following are the main causes of Python’s slowness:

  1. Being Translated: Python code, unlike native languages like C/C++, is interpreted at runtime rather than compiled to native code at build time. Python is an interpreted language, which means that the Python code we write must go through several abstraction steps before becoming machine code that can be executed.
  2. Compiler for Just In Time (JIT): Other interpreted languages, such as Java/.NET byte code, run quicker than Python byte code because they come with a JIT compiler that translates byte code into native code at runtime. Python does not have a JIT compiler since it is difficult to create one due to the dynamic nature of the language. It’s impossible to predict what kind of parameters will be supplied to a function, making optimization more difficult.
  3. GIL (Global Interpreter Lock): It prevents multi-threading by requiring the interpreter to run only one thread at a time within a single process (i.e. a Python interpreter instance).

 

Pretty interesting stuff!

 

If you want to learn more about Python, check out our course!

And if all this reading has got you considering a lower-level language that is faster, try out our Java course!

分享到 facebook
分享
分享到 linkedin
分享
分享到 twitter
鸣叫

相关文章

作者

IMG
汉娜
一个

关于 SCC

让所有学生在科技教育中获得乐趣和进步的重要性是我们的座右铭。我们希望我们的学生不仅为自己,也为社会创造更美好的未来。无论是为自己的电子游戏编程、为自己的卡通动画制作动画,还是构建机器人,我们的导师都可以通过我们的课程指导他们寻找更新的观点并探索未发现的发现。