Counting to 1 Billion (Node vs. Bun)

I was inspired by Ishaan Sheikh’s post here on counting to 1 billion: https://dev.to/sheikh_ishaan/count-to-1-billion-20de.

I wanted to see if there was a sizable performance difference in counting to 1 Billion in Javascript when using Node vs. when u…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Kunal Desai

I was inspired by Ishaan Sheikh's post here on counting to 1 billion: https://dev.to/sheikh_ishaan/count-to-1-billion-20de.

I wanted to see if there was a sizable performance difference in counting to 1 Billion in Javascript when using Node vs. when using Bun.

I ran this program and timed it using the MacOS time utility:

for (let i = 0; i < 1_000_000_000; i++) {
}

I ran it with Node and got:

node counter.js  0.46s user 0.03s system 84% cpu 0.578 total

Then, I ran it with Bun and got:

bun counter.js  0.90s user 0.01s system 99% cpu 0.912 total

I was surprised to see in something as simple as this the time difference was double for Bun vs. Node! Especially since Bun claimed that it was faster than Node since it uses Javascript Core instead of V8.

To verify this was the case, I tested it on 10,000,000,000. Here were the results:

node counter.js  7.87s user 0.06s system 97% cpu 8.118 total
bun counter.js  8.79s user 0.02s system 99% cpu 8.820 total

Clearly, it seems that there may be some bun startup/initialization cost that is causing the counting to be slower than Node. I'm curious to know where this is coming from.

Thanks to writethrough.io for helping me write this article.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Kunal Desai


Print Share Comment Cite Upload Translate Updates
APA

Kunal Desai | Sciencx (2022-11-07T00:02:54+00:00) Counting to 1 Billion (Node vs. Bun). Retrieved from https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/

MLA
" » Counting to 1 Billion (Node vs. Bun)." Kunal Desai | Sciencx - Monday November 7, 2022, https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/
HARVARD
Kunal Desai | Sciencx Monday November 7, 2022 » Counting to 1 Billion (Node vs. Bun)., viewed ,<https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/>
VANCOUVER
Kunal Desai | Sciencx - » Counting to 1 Billion (Node vs. Bun). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/
CHICAGO
" » Counting to 1 Billion (Node vs. Bun)." Kunal Desai | Sciencx - Accessed . https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/
IEEE
" » Counting to 1 Billion (Node vs. Bun)." Kunal Desai | Sciencx [Online]. Available: https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/. [Accessed: ]
rf:citation
» Counting to 1 Billion (Node vs. Bun) | Kunal Desai | Sciencx | https://www.scien.cx/2022/11/07/counting-to-1-billion-node-vs-bun/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.