
A Performance Reality Check
Synthetic Benchmarks vs Production Workloads
TL;DR
I was trying to compare the performance for my new project which involves sockets and high performance for low latency. I was using go as my primary language and I was confortable using go with gorilla/mux lib. Then soon I was hitted with the post from x.com which makes me think of using go once again.
I knew something is wrong in this test. Even shockingly the performance difference in go vs bun.js made me stop and think for a while. So I wanna to test the difference performance for this both language as an developer.
1. My Test VS Synthetic Benchmarks
In the Synthetic Benchmarks the tester just included a 1 bil nested for loop. This test just say how well the for loop is coded in a language and not the real performance.
// index.ts
for(var i = 0; i < n; i ++) {
for(var j = 0; j < n; j ++) {
...
...
...
}
}// main.go
for i := 0; i < n; i ++ {
for j := 0; j < n; j ++ {
...
...
..
}
}Btw noone is going to write 1b nested for loop. As an real developer Im not gonna to use. I want real performance how well the standard lib are written and how well the external lib are optimized.
In my test Im going to include:
- Setup a http server
- Data transformation (json)
- JWT
- Bcrypt
- Postgres Drivers
1.1. Go Test Setup
- Http Server: stock net/http with middleware chaining
- Json: standard lib encoding/json
- JWT Parsing: golang-jwt/jwt
- Bcrypt: crypto/bcrypt
- Database Driver: pgx/pgxpool
1.2. BunJS Test Setup
- Http Server: I choose HonoJS because it modern framework for building REST end points in JS.
- Json: HonoJS come with json encoding.
- JWT Parsing: jsonwebtoken
- Bcrypt: for password hashing function Bcrypt
- Database Driver: Im going to use pg.
both the language I gave the connection pool of the database of postgres to defaults by the drivers
Also I didn use any ORM because in JS lib like Drizzle or Prisma the SQL generated can fetch more than 2 times from the connection pool which may reduce the performance of JS.

