Is Python Really Slower than Java or C++

0
217
Is Python slower than Java or C++
Advertisement

In world of Programming or development we usually come across this question regularly. And this question also comes in your mind if you prefer to code in Python.

The short answer is yes, Python is slower than Java or C++.

But now the question is how much slower it is?

Now, If we do not look at the benchmark, and just see the online judges or online programming platforms like HackerRank or HackerEarth, we see that for a particular programming question, if the time provided for C or C++ is 1x then Java is having time 2x and Python is having time 5x. That indirectly means that if a program written C/C++ takes 1 Second to complete, then Python would take 5 Seconds to complete.

Now the question is if Python is slower than both Java or C++, then why Python is so much Popular?

The answer is very simple.

  1. Python is very Productive programming language. That means the development time in python is shorter than Java or C++.
  2. Python is easy to learn. That means any one from any background can learn and use Python very easily.
  3. Python is library reach. Almost all kind of Libraries can be found for Python.
  4. Python is framework reach. That means using one language we can develop web apps(Django/Flask), develop machine learning/deep learning(Scikit Learn/ TensorFlow/ Pytorch), develop android or IOS apps(Kivy)

So all these reasons combined makes Python a superior programming language for new comers. That is why python becomes so much popular.

Now the question is Why Python is slower than Java or C++?

Computers does not understand our high level English type programming language. So there are compilers which compiles our code to machine level codes, it makes our code understandable by computers.

C/C++ are compiled programming language. So after compilation it directly gets executed on that particular machine, which is very much faster nearly as assembly languages.

Where as Java is compiled as well as Interpreted Language which makes it little bit slower than C/C++ but faster than Python. Though some people says Java is nearly as much fast as C/C++.

Where as Python is purely interpreted language which means it interpret statement one by one and converts that to suitable machine level blocks of code. That makes it a lot slower.

Though now a days there are different run times available out there which makes python a lot faster such as CPython, PyPy etc.

Lets see the popularity graph of these languages for the last 5 years.

image
Python vs Java vs C++ for last 5 years

See? Python beats Java and becomes the most popular programming language now.

Advertisement