05/18/2023

Benchmarking Node JS vs Bun

Recently Bun added a compiling feature in version 0.6.1. Curious about its functionality, I conducted a comparison between compiled and uncompiled versions as a baseline. I also tested it against Node JS compiled with pkg. Here are the results!

Results

javascript"],["Bun.serve({"],["port: 3000,"],["async fetch(request) {"],["return new Response(\"Welcome to Bun!\");"],["},"],["});"],[""],[""],["#### Node"],["
javascript"],["const http = require(\"http\");"],[""],["const server = http.createServer((req, res) => {"],["res.end(\"Welcome to Node!\");"],["});"],["server.listen(3000, \"localhost\");"],["
"],["### Uncompiled Benchmarks"],[""],["#### Bun"],["
text"],["Running 30s test @ http://127.0.0.1:3000"],["12 threads and 400 connections"],["Thread Stats   Avg      Stdev     Max   +/- Stdev"],["Latency     1.19ms  190.99us  11.61ms   92.16%"],["Req/Sec    16.88k     5.16k   33.84k    57.33%"],["6061438 requests in 30.10s, 757.26MB read"],["Socket errors: connect 155, read 93, write 0, timeout 0"],["Requests/sec: 201346.62"],["Transfer/sec:     25.15MB"],["
"],[""],["#### Node"],["
text"],["Running 30s test @ http://127.0.0.1:3000"],["12 threads and 400 connections"],["Thread Stats   Avg      Stdev     Max   +/- Stdev"],["Latency     3.00ms  352.38us  27.28ms   98.85%"],["Req/Sec     6.74k     2.01k   16.86k    67.48%"],["2418249 requests in 30.10s, 320.56MB read"],["Socket errors: connect 155, read 113, write 0, timeout 0"],["Requests/sec:  80333.19"],["Transfer/sec:     10.65MB"],["
"],[""],["### Compiled Benchmarks"],[""],["#### Bun"],["To compile the server using Bun, I used the following command."],[""],["
text"],["bun build --compile bun_server.js"],["
"],[""],["##### Results"],[""],["
text"],["Running 30s test @ http://127.0.0.1:3000"],["12 threads and 400 connections"],["Thread Stats   Avg      Stdev     Max   +/- Stdev"],["Latency     1.18ms  194.89us   8.22ms   92.22%"],["Req/Sec    16.80k     6.94k   49.71k    60.40%"],["6029319 requests in 30.10s, 753.25MB read"],["Socket errors: connect 157, read 96, write 0, timeout 0"],["Requests/sec: 200285.12"],["Transfer/sec:     25.02MB"],["
"],[""],["#### Node"],["To compile a Node JS application into a single binary file I used the package `pkg` which was created by the founder of Vercel. It supports making a compile script that is able to automatically compile the server when run but for this test, I used the CLI command like below."],[""],["
text"],["pkg node_server.js"],["
"],[""],["For more information and installation instructions on `pkg` see [the official NPM page.](https://www.npmjs.com/package/pkg)"],[""],["##### Results"],["
text"],["Running 30s test @ http://127.0.0.1:3000"],["12 threads and 400 connections"],["Thread Stats   Avg      Stdev     Max   +/- Stdev"],["Latency     3.13ms  265.98us  21.10ms   98.80%"],["Req/Sec     6.46k     2.26k   10.97k    66.47%"],["2313736 requests in 30.04s, 306.71MB read"],["Socket errors: connect 155, read 108, write 0, timeout 0"],["Requests/sec:  77023.24"],["Transfer/sec:     10.21MB"],["
"],[""],["### Takeaways"],["Bun can be a lot faster than Node and it's going to be very exciting to see the further development of the project. This does not take away from Node however, Bun is still unstable as good as it is and it has a pretty different style that takes getting used to. I know that I will be using Bun in future projects but will stay with Node for anything that needs reliability. One thing that does need to be addressed before Bun can be seen as a competitor to Node is the documentation."]]'>
Back

Comments


Be the first to comment!

Read More

Warp Terminal screen shot
Warp Terminal screen shot

Warp Terminal

Warp terminal claims to be a "a blazingly fast, rust-based terminal reimagined from the ground up to work like...

Node JS Logo
Node JS Logo

Setting up Node.JS for production

Node.js is a popular JavaScript runtime that allows developers to build server-side applications with JavaScript. PM2 is a process manager for Node.js applications that helps to keep your applications running smoothly and automatically restart th...

Javascript Loops

Loops are one of the most valuable tools in any programmer's arsenal, and Javascript is no exception. Loops allow you to execute the same code multiple times with different values, making them a great way to deal with repetitive tasks. There are three main types of ...

Svelte Full Text Search - flexsearch

"flexsearch" is a JavaScript library for fast, flexible, and robust search and indexing. It provides a high-performance search engine that is optimized for search and indexing, and can be used in both client-side and server-side applications. It supports a range of features including full-text search, fuzzy...