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
What Age Does Car Insurance Go Down?
Log in or sign up to view
Christian McCaffrey loses fumble to open Super Bowl LVIII
Lexi Vonn
Nehemiah 4:1–23
Valley Fair Tickets Costco
Lenscrafters Westchester Mall
Ribbit Woodbine
Fallout 4 Pipboy Upgrades
My.doculivery.com/Crowncork
South Bend Tribune Online
Obituary | Shawn Alexander | Russell Funeral Home, Inc.
83600 Block Of 11Th Street East Palmdale Ca
Nashville Predators Wiki
Labor Gigs On Craigslist
Hellraiser III [1996] [R] - 5.8.6 | Parents' Guide & Review | Kids-In-Mind.com
Las 12 mejores subastas de carros en Los Ángeles, California - Gossip Vehiculos
The best TV and film to watch this week - A Very Royal Scandal to Tulsa King
Van Buren County Arrests.org
Hewn New Bedford
Graphic Look Inside Jeffrey Dahmer
Www.dunkinbaskinrunsonyou.con
Uncovering The Mystery Behind Crazyjamjam Fanfix Leaked
Gina Wilson Angle Addition Postulate
Low Tide In Twilight Ch 52
Mineral Wells Skyward
Geico Car Insurance Review 2024
Top 20 scariest Roblox games
Miles City Montana Craigslist
Ardie From Something Was Wrong Podcast
Danielle Moodie-Mills Net Worth
Tamil Movies - Ogomovies
Vadoc Gtlvisitme App
Craigslist Middletown Ohio
Craig Woolard Net Worth
Craigslist Texas Killeen
Metra Union Pacific West Schedule
Kelsey Mcewen Photos
Omnistorm Necro Diablo 4
Grapes And Hops Festival Jamestown Ny
3400 Grams In Pounds
When His Eyes Opened Chapter 2048
Kerry Cassidy Portal
Vons Credit Union Routing Number
Lamont Mortuary Globe Az
QVC hosts Carolyn Gracie, Dan Hughes among 400 laid off by network's parent company
Doublelist Paducah Ky
✨ Flysheet for Alpha Wall Tent, Guy Ropes, D-Ring, Metal Runner & Stakes Included for Hunting, Family Camping & Outdoor Activities (12'x14', PE) — 🛍️ The Retail Market
Contico Tuff Box Replacement Locks
Round Yellow Adderall
The Significance Of The Haitian Revolution Was That It Weegy
Karen Kripas Obituary
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.