Why Python is Popular Despite Being (Super) Slow

Why Python is Popular Despite Being (Super) Slow

Python is one of the most widely used programming languages, and it has been around for more than 28 years now. One common question arises in mind of most people, especially beginners and newbies, that why Python is popular in mainstream despite being slow? or why programmers or developers don?t care about speed and performance limitations in Python? In this post, I will go through some main reasons for this.

Image for post

Why is Python Slow in Terms of Speed?

Before diving into details of why Python is popular in mainstream despite being slow, I will shortly explain how or why Python is slow in nature in terms of performance and speed as compared to other popular programming languages like C and C++.

  • High-level programming language: With Python, the code looks very close to how humans think. For this purpose, it must abstract the details of the computer from you: memory management, pointers,? Hence, it is slower than ?lower-level language? like C;
  • Python is interpreted and not compiled: Sure, this statement is a gross simplification but it?s somehow correct. During the execution, Python code is interpreted at runtime instead of being compiled to native code at compile time;
  • Python is a dynamically typed language: Unlike ?statically-typed? languages like C, C++ or Java, you don?t have to declare the variable type like String, boolean or int. The less you do, the more your computer has to work. For each attribute access, tons of lookup is required. In addition, being very dynamic makes it incredibly hard to optimize Python;
  • Global Interpreter Lock (GIL): This GIL basically prevents multi-threading by mandating the interpreter only execute a single thread within a single process (an instance of the Python interpreter) at a time.

Image for post

Why is Python Still so Popular?

I would say that 9/10 times the slower performance of Python does not matter. Below I will discuss some major aspects and reasons.

9/10 times the slower performance of Python does not matter.

End-users just don?t care

Can you really feel the difference between 0.001 seconds or 0.01 seconds? The answer is most likely ?No?. Normally, it doesn?t matter too much to the end-users if your program takes just a little bit longer for its execution. As long as we don?t write a program which executes in centuries and totally destroys end-user experience, it?s fine. In case it takes too long, horizontal scaling can be used to solve many bottlenecks that would have been created by Python and make the execution faster.

More Productive

First and foremost reason why Python is much popular because it is highly productive as compared to other programming languages like C++ and Java. It is much more concise and expressive language and requires less time, effort, and lines of code to perform the same operations.

Image for postPython code is very simple and easy to read

The Python features like one-liners and dynamic type system allow developers to write very fewer lines of code for tasks that require more lines of code in other languages. This makes Python very easy-to-learn programming language even for beginners and newbies. For instance, Python programs are slower than Java, but they also take very less time to develop, as Python codes are 3 to 5 times shorter than Java codes.

Python is also very famous for its simple programming syntax, code readability and English-like commands that make coding in Python lot easier and efficient.

Execution Speed does not matter as much as Business Speed

There were times when computer run time was to be the main issue and the most expensive resource. But now, things have changed. Computer, servers and other hardware have become much much cheaper than ever and speed has become a less important factor. Today, development time matters more in most cases rather than execution speed in terms of cost as employee?s time has become one of the most, or even the most, expensive resource. Reducing the time needed for each project saves companies tons of money.

As far as the execution speed or performance of the program is concerned, we can easily manage it by horizontal scaling, means getting more servers running to get that level of speed or performance. In this modern era, where we have the very high computing power and multi-core processors that are becoming cheaper by the time, the speed and performance issues can easily be resolved. But it is not the same story for human cost. It will just keep increasing and increasing over time.

In short, the amount of time you can save in the development process will possibly be more and cost-effective than whatever performance and execution speed in the application you get.

Not only does the shorter development process save money, but also improves it your competitiveness. Faster prototype and deliver enable companies to innovate and get ahead of the competition.

As a CEO, which option will you choose? (1) complete a project in 6 months (2) complete exactly the same project in 4 months but you have to pay 20% more for the server. If execution speed is your most concern, then (1) is your choice. But if you focus on development speed and faster innovation, (2) should be your choice.

That?s where Python gains its popularity as the time required to build a program using Python very short as compared to other programming languages.

Is Speed the only factor you should consider?

When choosing any programming language to develop any type of application, there are several tens or hundreds of factors that you should consider, and speed is surely one of them. But, there are other things that also matter like language suitability.

Python has been in the market for a very long time and its community is very big. Thus, it is easy to find Python developers and supports.

In addition, the language has a rich set of standard libraries and frameworks for several purposes. For example, Django and Flask for developing web applications, TensorFlow for deep learning, and pandas for data analysis, etc.

Is Python Good for Speed-Intensive Applications?

So far we have discussed why Python is slow in terms of speed and why Python is popular in mainstream despite being slow. But, what if you strictly require high-performance and fast execution speed in certain applications? In this case, I would say that Python is no good. Sure, you can optimize it but in general, other programming languages should be used. For example, for game development, C# would be a better option.

In short, Python is widely used even when it is somehow slower than other languages because:

  • Python is more productive
  • Companies can optimize their most expensive resource: employees
  • Enable competitiveness improvement by fast innovation
  • Rich set of libraries and frameworks
  • Large community

But, it is also not suitable for speed-intensive applications including games that require high-performance and also OS or system-level applications.

21