Skip to content

基准

¥Benchmarks

基准只是基准,但对我们很重要。

¥Benchmarks are only benchmarks, but they are important to us.

路由

¥Routers

我们测量了一堆 JavaScript 路由的速度。例如,find-my-way 是 Fastify 内部使用的非常快的路由。

¥We measured the speeds of a bunch of JavaScript routers. For example, find-my-way is a very fast router used inside Fastify.

  • @medley/router

  • find-my-way

  • koa-tree-router

  • trek-router

  • express(包括处理)

    ¥express (includes handling)

  • koa-router

首先,我们向每个路由注册了以下路由。这些与现实世界中使用的类似。

¥First, we registered the following routing to each of our routers. These are similar to those used in the real world.

ts
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.

ts
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.

在 Node.js 上

¥On Node.js

以下截图显示了 Node.js 上的结果。

¥The following screenshots show the results on Node.js.

bench

bench

bench

bench

bench

bench

bench

bench

在 Bun 上

¥On Bun

以下截图显示了 Bun 上的结果。

¥The following screenshots show the results on Bun.

bench

bench

bench

bench

bench

bench

bench

bench

Cloudflare Workers

与 Cloudflare Workers 的其他路由相比,Hono 是最快的。

¥Hono is the fastest, compared to other routers for Cloudflare Workers.

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

与 Deno 的其他框架相比,Hono 是最快的。

¥Hono is the fastest, compared to other frameworks for Deno.

  • 机器:Apple MacBook Pro,32 GiB,M1 Pro,Deno v1.22.0

    ¥Machine: Apple MacBook Pro, 32 GiB, M1 Pro, Deno v1.22.0

  • 脚本:benchmarks/deno

    ¥Scripts: benchmarks/deno

  • 方法: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'

框架版本结果
Hono3.0.0请求数/秒:136112
快速4.0.0-beta.1请求数/秒:103214
Megalo0.3.0请求数/秒:64597
更快5.7请求数/秒:54801
oak10.5.1请求数/秒:43326
opine2.2.0请求数/秒:30700

另一个基准测试结果:denosaurs/bench

¥Another benchmark result: denosaurs/bench

Bun

Hono 是 Bun 最快的框架之一。你可以在下面看到它。

¥Hono is one of the fastest frameworks for Bun. You can see it below.

Hono v4.7 中文网 - 粤ICP备13048890号