Bun v/s Go: Hello world performance comparison (2024)

Bun v/s Go: Hello world performance comparison (1)

THIS IS AN OUTDATED ARTICLE. AN UPDATE HAS BEEN PUBLISHED HERE.

Continuing my quest of performance comparisons, this article is about Bun and Go. Who do you think is faster for a simple hello world case? In the previous comparison of Deno vs Go, we found that Deno’s native server is faster than Go’s native server. If Deno turned out to be faster, then it’s easy to conclude that Bun will be even faster because Bun is a bit faster than Deno. This time, too, the comparison is with Go’s net/http. Let’s find out the answer, which we already know!

The test is executed on MacBook Pro M1 with 16G of RAM. The test is executed using the well-known HTTP tester: Bombardier. It’s interesting to know that Bombardier itself is written in Go using fasthttp. However, this article compares Bun’s native HTTP server (Bun.serve) with Go’s native server (net/http). Very soon, there will be follow-up articles comparing Deno and Bun with Go’s fasthttp server.

The test is executed for 10, 50, 100, and 300 concurrent connections.

The code is:

Bun

Bun.serve({
port: 3000,
fetch(req) {
try {
if (req.method !== "GET") {
return new Response(null, { status: 405 });
}
const pathName = new URL(req.url).pathname;
if (pathName !== "/") {
return new Response(null, { status: 404 });
}
return new Response("Hello world");
} catch (e) {
return new Response(null, { status: 500 });
}
},
});

Go

package main

import (
"io"
"net/http"
)

func main() {
http.HandleFunc("/", helloWorld)
http.ListenAndServe(":3000", nil)
}

func helloWorld(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello world!")
}

A total of 10M (10 million) requests are executed for each concurrency level.

The following measurements are taken:

  • Time taken
  • Requests per second
  • Latencies: Mean, median, q25, q75, q90, maximum (in microseconds)
  • System usage: Average CPU and memory usage

Here are the charts representing results for each type of measurement (Note that all latencies are in microseconds):

Bun v/s Go: Hello world performance comparison (4)
Bun v/s Go: Hello world performance comparison (5)
Bun v/s Go: Hello world performance comparison (6)
Bun v/s Go: Hello world performance comparison (7)
Bun v/s Go: Hello world performance comparison (8)
Bun v/s Go: Hello world performance comparison (9)
Bun v/s Go: Hello world performance comparison (10)
Bun v/s Go: Hello world performance comparison (11)
Bun v/s Go: Hello world performance comparison (12)
Bun v/s Go: Hello world performance comparison (13)

This time I’m not surprised (and you’ll not be too!). Bun’s native server (Bun.serve) turns out to be quite faster than Go’s net/http server with comparatively less usage of the system resources. For 300 concurrent connections, Bun takes 57 seconds to finish off 10M requests, while Go takes 91 seconds. This is a big difference. Also, Bun uses half of Go’s CPU usage and the memory usage is almost the same.

Overall, Bun’s native server easily beats Go’s built-in native server.

Bun v/s Go: Hello world performance comparison (2024)
Top Articles
Ratgeber - Echtheit von Gold prüfen | BROGLE
11 Best Trader Joe's Chicken Products to Buy
Walgreens Boots Alliance, Inc. (WBA) Stock Price, News, Quote & History - Yahoo Finance
Monthly Forecast Accuweather
Pnct Terminal Camera
DEA closing 2 offices in China even as the agency struggles to stem flow of fentanyl chemicals
St Als Elm Clinic
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Zitobox 5000 Free Coins 2023
5 Bijwerkingen van zwemmen in een zwembad met te veel chloor - Bereik uw gezondheidsdoelen met praktische hulpmiddelen voor eten en fitness, deskundige bronnen en een betrokken gemeenschap.
Emmalangevin Fanhouse Leak
Ribbit Woodbine
What's Wrong with the Chevrolet Tahoe?
Noaa Weather Philadelphia
Osrs But Damage
7 Low-Carb Foods That Fill You Up - Keto Tips
Industry Talk: Im Gespräch mit den Machern von Magicseaweed
The most iconic acting lineages in cinema history
Peraton Sso
Nhl Wikia
Toy Story 3 Animation Screencaps
Pirates Of The Caribbean 1 123Movies
Shreveport City Warrants Lookup
Harbor Freight Tax Exempt Portal
New Stores Coming To Canton Ohio 2022
Craigslist Brandon Vt
Big Boobs Indian Photos
In hunt for cartel hitmen, Texas Ranger's biggest obstacle may be the border itself (2024)
Emuaid Max First Aid Ointment 2 Ounce Fake Review Analysis
Elanco Rebates.com 2022
O'reilly Auto Parts Ozark Distribution Center Stockton Photos
What Time Does Walmart Auto Center Open
Shnvme Com
Old Peterbilt For Sale Craigslist
A Man Called Otto Showtimes Near Amc Muncie 12
Autozone Locations Near Me
Atlanta Musicians Craigslist
Gary Lezak Annual Salary
Prior Authorization Requirements for Health Insurance Marketplace
Wasmo Link Telegram
Chathuram Movie Download
Weather In Allentown-Bethlehem-Easton Metropolitan Area 10 Days
Amc.santa Anita
Charli D'amelio Bj
Stranahan Theater Dress Code
R: Getting Help with R
Studentvue Calexico
Nearest Wintrust Bank
Mcoc Black Panther
Black Adam Showtimes Near Kerasotes Showplace 14
Where and How to Watch Sound of Freedom | Angel Studios
Craigslist Psl
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 6018

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.