The JS runtimes
Published in

The JS runtimes

Bun v/s Go: Hello world performance comparison — Part 2 fasthttp

In the previous article, I’ve compared Bun’s native HTTP server (Bun.serve) with Go’s net/http server. Go turned out slower than Bun. As promised in the previous article, I’m now comparing Bun’s native HTTP server with Go’s server based on the popular fasthttp framework. Let’s find out if fasthttp makes Go faster than Bun.

Setup

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. This article compares Deno’s native HTTP server (Deno.serve) with Go’s server based on the fasthttp framework. The test is executed for 10, 50, 100, and 300 concurrent connections.

The software versions are:

  • Bun v0.5.4
  • Go v1.19.5

The code is:

Bun

Bun.serve({
port: 3000,
fetch(_) {
return new Response("Hello world!");
},
});

Go

package main

import (
"fmt"
"github.com/valyala/fasthttp"
)

func main() {
fasthttp.ListenAndServe(":3000", helloWorld)
}

func helloWorld(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello world!")
ctx.SetContentType("text/plain; charset=utf8")
}

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

Results

Here are the charts representing results for each type of measurement:

(Note that all latencies are in microseconds)

Yes, Go with fasthttp makes it at par with Bun, but not better than Bun. As we saw in the comparison with Deno, Bun also uses less CPU, while Go uses less memory.

More articles on similar topics can be seen in the magazine: The JS runtimes.

--

--

Articles on the popular JS runtimes, Node.js, Deno, and Bun

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store