Benchmark methodology
GritvsBun

Grit vs Bun

Bun advertises itself on speed, so it deserves its best configuration: Bun.serve directly, Bun’s built-in SQL client, no framework and no ORM. That is the setup Bun’s own published benchmarks use.

Bun 1.3, Bun.serve, Drizzle ORM · v1.3 + Drizzle

What you should end up with

ScenarioGritBunRatio
show
GET /api/v1/products/:id
4,536 req/s
8.2 ms · neither saturated
2,717 req/s
16.2 ms · its own ceiling
1.67×
write
POST /api/v1/products
4,959 req/s
7.7 ms · neither saturated
2,224 req/s
18.0 ms · its own ceiling
2.23×
list
GET /api/v1/products?page=N&page_size=20
615 req/s
65.6 ms · database-bound
590 req/s
70.8 ms · database-bound
1.04×
mixed
a weighted blend of the three above
568 req/s
70.9 ms · database-bound
621 req/s
65.8 ms · database-bound
0.91×

Both figures come from the same run, minutes apart. Your absolute numbers will differ (different CPU, different disk, different background load) and so will ours: Grit's single-row read measured 4,536 req/s in the Bun pair and 8,509 in the Express pair from an identical binary, as hours of write scenarios accumulated in Postgres. The ratio is what should survive. If it does not, something in the setup differs and the steps below are where to look.

How Bun is kept from being handicapped

A benchmark is only worth publishing if the loser was given every reasonable advantage. These are the specific decisions made for this framework, and each one is worth saying out loud on camera.

  • Bun.serve with hand-rolled routing. Elysia or Hono would add overhead Bun does not need to pay: this is Bun at its fastest.
  • Drizzle over Bun’s built-in SQL client. Drizzle is what Bun projects actually use (TypeScript-native, no query engine binary, no fight with the runtime) and using an ORM at all matters because Grit’s generated handlers use GORM and cannot swap it out.
  • One process per CPU sharing the socket via `reusePort`. Bun.serve is single-threaded per process, so a lone process would leave three of four cores idle.
  • Connection pool max of 100, matching every other framework here.

Reproduce it, start to finish

  1. 1

    Install the two tools you need

    Docker runs every app and the database. k6 generates the load. Nothing else is required: you do not need Go, PHP, Python, Node or Bun installed locally, because every framework builds inside a container.

    # macOS
    brew install k6
    # Windows
    winget install k6 --source winget
    # Linux
    sudo gpg -k && sudo gpg --no-default-keyring \
    --keyring /usr/share/keyrings/k6-archive-keyring.gpg \
    --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
    echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" \
    | sudo tee /etc/apt/sources.list.d/k6.list
    sudo apt-get update && sudo apt-get install k6
    k6 version
    docker --version
  2. 2

    Clone the harness

    Everything below lives in the benchmarks directory of the Grit repository: the compose file, the k6 script, the seed data, and each framework’s application.

    git clone https://github.com/MUKE-coder/grit.git
    cd grit/benchmarks
  3. 3

    Start Postgres and create the databases

    One Postgres instance is shared by every framework, tuned once, with 8 CPUs: deliberately more than any application gets, so the database is never what gives out first. Each framework gets its own database so their schemas cannot collide.

    docker compose up -d postgres
    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -q -U bench -d bench -c "CREATE DATABASE $db;"
    done
  4. 4

    Create the table and load identical rows

    This is the single most important step for a fair result. Every framework gets the same table, created from the same SQL file, holding the same 10,000 rows with the same UUIDs. Letting each ORM run its own migration would mean comparing schemas, not frameworks: Eloquent, Django and GORM disagree about integer widths, timestamp precision and which columns get indexed.

    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -q -U bench -d $db < seed/schema.sql
    docker compose exec -T postgres psql -q -U bench -d $db < seed/products.sql
    done
    # every one should print 10000
    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -tA -U bench -d $db -c "SELECT count(*) FROM products;"
    done

    If any of these prints something other than 10000, stop and fix it. A benchmark where one side has more rows than another is measuring the row count.

  5. 5

    Look at the Bun server

    bun-bench/server.ts is a single fetch handler with hand-written routing for four endpoints. start.ts forks one server process per CPU.

    cat bun-bench/server.ts
    cat bun-bench/start.ts
  6. 6

    Note reusePort, and why it is essential

    This is what lets several Bun processes share one listening socket. Without it you get "address already in use" on the second worker, and if you then give up and run a single process you have quietly handed Bun a quarter of the CPU everyone else gets.

    Bun.serve({
    port: 8080,
    hostname: '0.0.0.0',
    reusePort: true, // several processes, one socket
    async fetch(req) { /* ... */ },
    })
  7. 7

    Build and start it

    Bun’s official Alpine image, production install.

    docker compose build bun
    docker compose up -d bun
    # should print: bun-bench: forking 4 workers
    docker compose logs bun | head -3
  8. 8

    Check every framework is on an ORM, not raw SQL

    This is the fairness decision that matters most after the shared schema. Grit’s generated handlers use GORM and you cannot swap that out, so measuring any framework against hand-written SQL compares an ORM to no ORM, which flatters that framework for a reason that has nothing to do with it. Express on raw pg measured 2,000 req/s on writes; the same Express on Prisma measured 773. Same framework, same machine, same test.

    # Grit GORM apps/api/internal/models/product.go
    # Laravel Eloquent laravel-bench/app/Models/Product.php
    # Django Django ORM django-bench/products/models.py
    # Express Prisma express-bench/prisma/schema.prisma
    # Next.js Prisma nextjs-bench/prisma/schema.prisma
    # Bun Drizzle bun-bench/schema.ts
    # Encore Drizzle encore-bench/products/schema.ts
    grep -rl "prisma|drizzle|Eloquent|models.Model" express-bench nextjs-bench bun-bench encore-bench django-bench laravel-bench 2>/dev/null | head

    If you swap any of these for raw SQL the numbers move enough to change the conclusion. That is the single easiest way to make this benchmark say whatever you want it to say.

  9. 9

    Prove the two apps return the same bytes

    Before measuring anything, confirm the framework you are testing returns exactly what Grit returns for the same record. If the payloads differ, say a missing field or a price as a string instead of a number, then the two are doing different amounts of work and the comparison is void.

    ID=$(python -c "import json;print(json.load(open('seed/ids.json'))[0])")
    for app in grit bun; do
    echo "--- $app"
    docker run --rm --network benchmarks_default curlimages/curl -s \
    "http://$app:8080/api/v1/products/$ID"
    echo
    done

    This is the step most benchmarks skip, and it is the one that decides whether the rest means anything. Show it on camera.

  10. 10

    Run the benchmark

    Three repetitions of four scenarios, one application at a time with the others stopped. Each run resets the dataset first, discards a warm-up, and samples container CPU while the load is actually running.

    APPS="grit bun" REPS=3 ./final.sh
    python aggregate.py

Reading your own results

Bun is the fastest JavaScript runtime in this comparison by a clear margin, which matches its reputation, and it is the one framework here that beats Grit at something: inserts, by about a quarter. Watch the CPU column on the single-row read, because it changes what the numbers mean. Bun pins its container at 407% of a 400% allowance while Grit sits at 306% with Postgres at 262%, so Bun is at its ceiling there and Grit is not. On list and mixed both sides are waiting on Postgres, which is why those two ratios sit close to 1.

aggregate.py prints the app container's CPU and Postgres's CPU next to every row. That pair is what tells you whether a number is a real ceiling. If the app is pinned near 400% then you are seeing its limit. If the app is idling while Postgres is near 800%, the database gave out first. That row is a floor, the framework would go faster on a bigger database, and quoting it as “X does N req/s” overstates what you measured.

The other guides