Skip to content

Commit cd3401d

Browse files
bench: add realistic workload benchmarks
Add comprehensive benchmarks with real-world API route sets (e-commerce 108 routes, GitHub-like 119 routes), route scaling tests (50/200/500), findAllRoutes, removeRoute, compilation time, and memory usage measurements. Document results in README. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f6a5b4d commit cd3401d

4 files changed

Lines changed: 830 additions & 0 deletions

File tree

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,57 @@ const compilerCode = compileRouterToString(router, "findRoute");
201201

202202
<!--/automd -->
203203

204+
## Benchmarks
205+
206+
Performance benchmarks on **Apple M3 Max** with **Node.js 24** (using [mitata](https://github.com/evanwashere/mitata)):
207+
208+
### Realistic API Workloads
209+
210+
| Scenario | Compiled | Interpreter | Speedup |
211+
|---|---|---|---|
212+
| E-commerce API (108 routes, 33 requests) | **1.46 µs** | 3.67 µs | 2.5x |
213+
| GitHub-like API (119 routes, 29 requests) | **886 ns** | 4.90 µs | 5.5x |
214+
| findAllRoutes (overlapping, 6 requests) | **995 ns** | 1.58 µs | 1.6x |
215+
216+
### Route Type Latency (compiled, single lookup)
217+
218+
| Route Type | Avg Latency |
219+
|---|---|
220+
| Miss (not found) | **93 ns** |
221+
| Static | **98 ns** |
222+
| Wildcard | **253 ns** |
223+
| Param (`:id`) | **528 ns** |
224+
225+
### Scaling
226+
227+
| Route Count | Compiled Lookup | Memory |
228+
|---|---|---|
229+
| 50 routes | 1.78 µs | ~31 KB |
230+
| 200 routes | 8.53 µs | ~126 KB |
231+
| 500 routes | 16.47 µs | ~322 KB |
232+
233+
### Build Performance
234+
235+
| Operation | 108 routes | 200 routes |
236+
|---|---|---|
237+
| `addRoute` | 78 µs | 143 µs |
238+
| `compileRouter` | 58 µs | 106 µs |
239+
240+
### Running Benchmarks
241+
242+
```bash
243+
# Existing micro-benchmarks
244+
pnpm bench:node
245+
pnpm bench:bun
246+
pnpm bench:deno
247+
248+
# Realistic workload benchmarks
249+
pnpm bench:realistic # Node.js (default: 6 groups)
250+
pnpm bench:realistic -- --full # All groups (+ single latency, removeRoute, deep params)
251+
pnpm bench:realistic:bun # Bun
252+
pnpm bench:realistic:deno # Deno
253+
```
254+
204255
## License
205256

206257
<!-- automd:contributors license=MIT author="pi0" -->

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"bench:bun": "bun ./test/bench",
1919
"bench:deno": "deno run -A ./test/bench/index.ts",
2020
"bench:node": "node --expose-gc --allow-natives-syntax --disable-warning=ExperimentalWarning --experimental-strip-types ./test/bench/index.ts",
21+
"bench:realistic": "node --expose-gc --disable-warning=ExperimentalWarning --experimental-strip-types ./test/bench/realistic.ts",
22+
"bench:realistic:bun": "bun ./test/bench/realistic.ts",
23+
"bench:realistic:deno": "deno run -A ./test/bench/realistic.ts",
2124
"build": "obuild",
2225
"dev": "vitest",
2326
"lint": "oxlint . && oxfmt --check src test",

0 commit comments

Comments
 (0)