Count to 1 Billion – Dev Community

Unsplash. On cover image by Marcus Krysetya

Over the weekend and out of curiosity after watching this video on YouTube, I thought of doing a similar experiment comparing the execution speeds of different programming languages ​​that loop from 0 to 1 billion.

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

Language Time taken (in seconds)
node.js 1.68s
golang 2.5s
C# 3.05p
c++ 3.49s
War 25.18s
PHP 25.31s
ruby 128.17s
Python 159s

I have used windows powershell Measure-Command Time to time commands for the execution of the program.

I have written some program like below in different programming languages.

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

exit fullscreen mode

i have used for Loops in all programming languages ​​I’ve used.

system configuration

The details of the computer I have used for the experiment are given below-
Processor – Intel Core i3-6006U CPU @ 2.00 GHz | 2 crore
to hit – 8 GB
Operating System – Windows 10

conclusion

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

PS – I did this experiment just for curiosity and it is not intended to show whether one programming language is better than another. Each language is designed for specific use-cases. And I also like many programming languages.

Feel free to share results for other programming languages ​​I didn’t test for.

Leave a Comment