An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
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.
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 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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To