Express (Bun) vs Springboot: Hello world performance comparison
--
In one of the previous article, where I compared Bun’s native HTTP server with spring, I got comments that the comparison wasn’t fair. Spring is a framework, therefore it should be compared with a framework on the Bun side: Express, Fastify, etc. A very valid point.
At the time of writing, fastify doesn’t work with Bun.
This article compares a hello world app in express running on Bun with a hello world app in springboot. It’s well known that express is quite slow. I don’t expect it to perform better than spring. However, with Bun, express might stand a chance in front of spring. The test setup is the same: MacBook M1 with 16G RAM. Bun v0.5.7 is compared with spring 3.0.4 over Java 17.
The code is as follows:
Bun
const express = require("express");
const app = express();
const port = 3000;
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(port, () => console.log("Listening on", port));
Spring
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/")
public String handleRequest() {
return "Hello World!";
}
}
The test runs for a total of 5M requests for 25, 100, 200, and 300 concurrent connections. The testing tool is bombardier which is known to be very fast.
Let’s jump straight to the results.
With Bun, the express app works faster, but still gets beaten by springboot. The CPU and memory usage is also pretty high with express.
WINNER: Springboot