Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 6, 2022 12:27 pm GMT

Count to 1 billion

Cover image by Markus Krisetya on Unsplash

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 which runs a loop from 0 to 1 billion.

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.

LanguageTime taken (in seconds)
Node.js1.68s
Golang2.5s
C#3.05s
C++3.49s
Rust25.18s
PHP25.31s
Ruby128.17s
Python159s

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

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

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

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

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.

Feel free to share the result of other programming languages which I didn't tested for.


Original Link: https://dev.to/sheikh_ishaan/count-to-1-billion-20de

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To