Skip to main content

Benchmarks

还没翻译译自英文(hono.dev)本页 39 段都还没译

模型写的

背景主张方法设置结果

Benchmarks

尽管基准测试只是基准测试,它对 Hono 仍然重要

Benchmarks are only benchmarks, but they are important to us.Benchmarks are only benchmarks, but they are important to us.基准测试只是基准测试,但 Hono 重视它 尽管有局限,本页仍将基准数字视为有意义的参考基准测试只是基准测试,但 Hono 重视它基准测试

Routers

We measured the speeds of a bunch of JavaScript routers. For example, find-my-way is a very fast router used inside Fastify.We measured the speeds of a bunch of JavaScript routers. For example, find-my-way is a very fast router used inside Fastify.测量了多种 JavaScript 路由的速度,包括 find-my-way Fastify 内使用的极快路由器 find-my-way 设定了对比基准测量了多种 JavaScript 路由的速度,包括 find-my-way路由速度

  • @medley/router
    @medley/router
    @medley/router
    @medley/router
    @medley/router
  • find-my-way
    find-my-way
    find-my-way
    find-my-way
    find-my-way
  • koa-tree-router
    koa-tree-router
    koa-tree-router
    koa-tree-router
    koa-tree-router
  • trek-router
    trek-router
    trek-router
    trek-router
    trek-router
  • express (includes handling)
    express (includes handling)
    express(包含处理)
    express(包含处理)
    express
  • koa-router
    koa-router
    koa-router
    koa-router
    koa-router

First, we registered the following routing to each of our routers. These are similar to those used in the real world.First, we registered the following routing to each of our routers. These are similar to those used in the real world.每个路由器都注册了十二条接近真实的路径 使用贴近真实的路径模式使基准测试更接近生产环境每个路由器都注册了十二条接近真实的路径注册路由

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/*' },
]

Then we sent the Request to the endpoints like below.Then we sent the Request to the endpoints like below.向七种端点类型发送请求,包括通配符和 post 短静态、动态和通配符各自考验不同的路由路径向七种端点类型发送请求,包括通配符和 post请求端点

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',
  },
]

Let's see the results.Let's see the results.让我们看看结果让我们看看结果让我们看看结果

On Node.js

截图展示了 Node.js 上的路由基准结果

The following screenshots show the results on Node.js.The following screenshots show the results on Node.js.截图展示了 Node.js 上的路由基准结果 这些按请求类型划分的图片是该平台唯一公布的数值截图展示了 Node.js 上的路由基准结果Node.js 结果

On Bun

截图展示了 Bun 上的路由基准结果

The following screenshots show the results on Bun.The following screenshots show the results on Bun.截图展示了 Bun 上的路由基准结果 Bun 单独运行与 Node.js 相同的路由基准截图展示了 Bun 上的路由基准结果Bun 结果

Cloudflare Workers

Hono 达到每秒 402,820 次操作,是 Cloudflare Workers 路由器中最快的

Hono is the fastest, compared to other routers for Cloudflare Workers.Hono is the fastest, compared to other routers for Cloudflare Workers.Hono 是 Cloudflare Workers 上最快的路由器 在该平台上它与其他路由器而非框架进行比较Hono 是 Cloudflare Workers 上最快的路由器Workers 最快

  • Machine: Apple MacBook Pro, 32 GiB, M1 Pro
    Machine: Apple MacBook Pro, 32 GiB, M1 Pro
    机器:Apple MacBook Pro,32 GiB,M1 Pro
    机器:Apple MacBook Pro,32 GiB,M1 Pro
    机器
  • Scripts: benchmarks/handle-event
    脚本:benchmarks/handle-event
    脚本:benchmarks/handle-event
    脚本
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 每秒处理 136112 个请求,是 Deno 框架中最快的

Hono is the fastest, compared to other frameworks for Deno.Hono is the fastest, compared to other frameworks for Deno.Hono 是 Deno 上最快的框架 它在此与其他 Deno 框架而非路由器比较Hono 是 Deno 上最快的框架Deno 最快

  • Machine: Apple MacBook Pro, 32 GiB, M1 Pro, Deno v1.22.0
    Machine: Apple MacBook Pro, 32 GiB, M1 Pro, Deno v1.22.0
    机器:Apple MacBook Pro,32 GiB,M1 Pro,Deno v1.22.0
    机器:Apple MacBook Pro,32 GiB,M1 Pro,Deno v1.22.0
    机器
  • Scripts: benchmarks/deno
    脚本:benchmarks/deno
    脚本:benchmarks/deno
    脚本
  • Method: bombardier --fasthttp -d 10s -c 100 'http://localhost:8000/user/lookup/username/foo'
    Method: bombardier --fasthttp -d 10s -c 100 'http://localhost:8000/user/lookup/username/foo'
    Hono 3.0.0 使用 bombardier 达到每秒 136112 个请求 在同一压测命令下它超过了 Fast、Megalo、Faster、oak 和 opine
    Hono 3.0.0 使用 bombardier 达到每秒 136112 个请求
    每秒请求
FrameworkVersionResults
Hono3.0.0Requests/sec: 136112
Fast4.0.0-beta.1Requests/sec: 103214
Megalo0.3.0Requests/sec: 64597
Faster5.7Requests/sec: 54801
oak10.5.1Requests/sec: 43326
opine2.2.0Requests/sec: 30700

Another benchmark result: denosaurs/benchAnother benchmark result: denosaurs/bench另一份基准结果:denosaurs/bench另一份基准结果:denosaurs/bench其他基准

Bun

Hono 是 Bun 上最快的框架之一

Hono is one of the fastest frameworks for Bun. You can see it below.Hono is one of the fastest frameworks for Bun. You can see it below.Hono 是 Bun 上最快的框架之一 这一说法比 Deno 更温和,只把 Hono 列为领先者而非第一Hono 是 Bun 上最快的框架之一Bun 最快