During the weekend and out of curiosity after watching this video on YouTube, I thought of doing a similar experiment of comparing the execution speed of different programming languages.

So, I wrote a similar program in some of the popular programming languages and timed the execution of the program. Each program contains a loop from 0 to 1 billion. The following table contains the result of the experiment.

Language Time taken (in seconds)
Node.js 1.68s
Golang 2.5s
C# 3.05s
C++ 3.49s
Rust 25.18s
PHP 25.31s
Ruby 128.17s
Python 159s

I have used the Windows PowerShell Measure-Command command to time the execution of the program.

I wrote a program something similar to the below in different programming languages.

count = 0
for i in range(1000000000):
    count += 1

I have used the for loop in all the programming languages.

Note: I have executed all the programs in debug mode. The results in release mode (with optimization) may be different.

System configurations

Below are the details of the computer I have used for the experiment-

Processor - Intel Core i3-6006U CPU @ 2.00 GHz | 2 Cores

RAM - 8 GB

Operating System - Windows 10

Conclusion

I was expecting C++ and Rust to top the table but surprisingly Node.js beats them all. And Rust is not even close to C++. Python is the worst performer. I don’t know the exact reason for this behavior but it might be related to the architecture of the languages.

P.S - I have done this experiment just for out of curiosity and it is not intended to show if a programming language is better than the other. Every language is designed for the specific use-cases. And I love multiple programming languages too.