Why is Python slower than JavaScript?

Liang Han Sheng
5 min readJun 22, 2022

--

Is it true that python is slower than JavaScript? Before digging into this truth, let’s go through the history of these two programming languages and the facts about them.

In this article, we will focus on these topics:

  • Introduction to JavaScript and Python
  • Where does JavaScript win Python?
  • Performances
  • Scalability
Photo by the author

A Quick Introduction To JavaScript And Python

What is Python?

We not gonna talk about the snake but a high-level programming language. Python is developed by Guido van Rossum and introduced in 1991. It is one of the most popular programming languages as it is readable, maintainable, and easy to use and has been loved by a lot of developers and beginners. Python is considered a “very powerful and clear object-oriented programming language”. Users can download it for free as it is available under the GNU General Public License (GPL).

Python's now powerful and versatility have made it an indispensable tool in virtually every scientific application around the world. It is a general-purpose programming language that is compatible with various programming paradigms.

It is widely used in data science, artificial intelligence, machine learning, computer science education, computer vision and image processing, medicine, biology, and even astronomy.

What is JavaScript?

JavaScript has been created by Brendan Eich(Netscape) in 1995, but it is now maintained by ECMA. JavaScript is a high-level programming and is distinguished for its dynamic typing and just-in-time(JIT) compiler. A question that people keep debating is “ Is Javascript an object-oriented programming language?”. Well, although it is not a ‘pure’ object-oriented programming language, it does support some object-oriented principles, such as encapsulation and polymorphism.

Back then, React was launched by the Facebook engineering team in 2013, and it immediately grew popular, reinforcing JavaScript’s place as the web’s preferred workhorse.

But when it comes to popularity, JavaScript is a bit inferior compared to Python, since JavaScript is not that readable and also hard to learn for beginners.

Photo by the author

Where does JavaScipt win python?

Python is used for back-end development, which is mainly for web development and is responsible for developing ‘elements’ that users are not able to see. In another word, it‘s server-side implementation.

While Python can be used as the back-end part of a web application, JavaScript can be used to develop both the back-end and the front-end of the application. The front-end is the ‘antonym’ of the back-end development which creates the part that users are able to see and interact with; also known as the user interface. JavaScript is a great choice for creating web and mobile applications. It provides several great frameworks for developers to design their web pages and mobile apps. For instance, React Native, Angular, and Vue. In contrast, Python is widely used in scientific and specialized applications as we mentioned (data science, artificial intelligence, machine learning, etc…)

Performances

One of the main aims of JavaScript was about being fast on the web. Compared with Python, Node.js has a faster performance because of its advanced multithreading capabilities. In contrast to Python, which must process all requests in a single flow.

JavaScript allows us to process massive amounts of data in seconds and stream that information back to our end-user without requiring an army of servers to keep up with all those requests. For instance, it works well in collaboration tools (real-time applications) and notification systems such as stock notifications for a stock trader. Thus, it has significantly reduced the time users wait for the pages to load!

On the other hand, Python is a better option for processing vast amounts of data in machine learning where to solve a specific problem. Due to its readability and easiness of use, it has been loved by a lot of developers and also novices.

Furthermore, even though Python might take longer to respond, there are some methods for improving its performance by benefiting from the C programming language with Numpy and Cython. As Cython is a Python compiler, it allows developers to create fast C modules, which speeds up the execution of raw Python code.

Scalability

There is a sightly difference when it comes to scalability. Python uses a global interpreter lock (GIL), in simple words, it is a lock, also known as mutex (What is GIL?) which allows only one thread to hold and control the Python interpreter. However, GIL ensures only one thread can be running at any given time.

Obviously, GIL causes it harder to use multiple processors with thread but the multiprocessing library, as a tool from python itself — is allowed to use by developers to fully leverage multiple processors on a particular machine.

Therefore, multithreading makes JavaScript stands out from other programming languages as it allows for increased scalability by expanding the number of threads.

Photo by the author

Conclusion

To top it off, Python and Javascript are very powerful languages with different real-world applications, whether you are a developer or a beginner, you can delve into the well and also explore their excellent libraries and frameworks.

They have significant differences, but they both share the basic elements required to write powerful programs.

Thanks for reading, and if you found this article helpful, you might want to check out my other articles as well!

Want to Connect?

This article is written by Han Sheng, Technical Lead in Arkmind, Malaysia. He has a passion for Software Design/Architecture related stuff, Computer Vision and also Edge Devices. He made several AI-based Web/Mobile Applications to help clients solving real-world problems. Feel free to read about him via his Github profile.

--

--

Liang Han Sheng
Liang Han Sheng

Written by Liang Han Sheng

Loan Origination Solutions Provider | Full Stack AI Application Development

No responses yet