Skip to content

벤치마크

벤치마크는 단순히 벤치마크일 뿐이지만, 여전히 우리에게 중요한 의미를 가진다.

라우터

여러 자바스크립트 라우터의 성능을 측정했다. 예를 들어, find-my-way는 Fastify 내부에서 사용되는 매우 빠른 라우터다.

  • @medley/router
  • find-my-way
  • koa-tree-router
  • trek-router
  • express (핸들링 포함)
  • koa-router

먼저, 각 라우터에 다음과 같은 라우팅을 등록했다. 이 라우팅은 실제 환경에서 사용되는 것과 유사하다.

ts
interface Route {
  method: string
  path: string
}
// ---cut---
export const routes: Route[] = [
  { method: 'GET', path: '/user' },
  { method: 'GET', path: '/user/comments' },
  { method: 'GET', path: '/user/avatar' },
  { method: 'GET', path: '/user/lookup/username/:username' },
  { method: 'GET', path: '/user/lookup/email/:address' },
  { method: 'GET', path: '/event/:id' },
  { method: 'GET', path: '/event/:id/comments' },
  { method: 'POST', path: '/event/:id/comment' },
  { method: 'GET', path: '/map/:location/events' },
  { method: 'GET', path: '/status' },
  { method: 'GET', path: '/very/deeply/nested/route/hello/there' },
  { method: 'GET', path: '/static/*' },
]

그리고 아래와 같은 엔드포인트로 요청을 보냈다.

ts
interface Route {
  method: string
  path: string
}
// ---cut---
const routes: (Route & { name: string })[] = [
  {
    name: 'short static',
    method: 'GET',
    path: '/user',
  },
  {
    name: 'static with same radix',
    method: 'GET',
    path: '/user/comments',
  },
  {
    name: 'dynamic route',
    method: 'GET',
    path: '/user/lookup/username/hey',
  },
  {
    name: 'mixed static dynamic',
    method: 'GET',
    path: '/event/abcd1234/comments',
  },
  {
    name: 'post',
    method: 'POST',
    path: '/event/abcd1234/comment',
  },
  {
    name: 'long static',
    method: 'GET',
    path: '/very/deeply/nested/route/hello/there',
  },
  {
    name: 'wildcard',
    method: 'GET',
    path: '/static/index.html',
  },
]

결과를 살펴보자.

Node.js에서의 결과

다음 스크린샷은 Node.js에서의 결과를 보여준다.

bench

bench

bench

bench

bench

bench

bench

bench

Bun에서의 결과

다음 스크린샷은 Bun에서의 결과를 보여준다.

bench

bench

bench

bench

bench

bench

bench

bench

Cloudflare Workers

Hono는 다른 Cloudflare Workers 라우터와 비교했을 때 가장 빠르다.

javascript
Hono x 402,820 ops/sec ±4.78% (80 runs sampled)
itty-router x 212,598 ops/sec ±3.11% (87 runs sampled)
sunder x 297,036 ops/sec ±4.76% (77 runs sampled)
worktop x 197,345 ops/sec ±2.40% (88 runs sampled)
Fastest is Hono
✨  Done in 28.06s.

Deno

Hono는 Deno용 프레임워크 중에서 가장 빠르다.

  • 머신: Apple MacBook Pro, 32 GiB, M1 Pro, Deno v1.22.0
  • 스크립트: benchmarks/deno
  • 방법: bombardier --fasthttp -d 10s -c 100 'http://localhost:8000/user/lookup/username/foo'
프레임워크버전결과
Hono3.0.0초당 요청: 136112
Fast4.0.0-beta.1초당 요청: 103214
Megalo0.3.0초당 요청: 64597
Faster5.7초당 요청: 54801
oak10.5.1초당 요청: 43326
opine2.2.0초당 요청: 30700

추가 벤치마크 결과: denosaurs/bench

Bun

Hono는 Bun에서 가장 빠른 프레임워크 중 하나다. 아래 링크에서 확인할 수 있다.

Released under the MIT License.