コンテンツにスキップ

ベンチマーク

ベンチマークはあくまでもベンチマークですが、私たちにとって重要です。

ルーター

私たちは多数のJavaScriptルーターの速度を測定しました。例えば、find-my-wayはFastify内部で使用されている非常に高速なルーターです。

  • @medley/router
  • find-my-way
  • koa-tree-router
  • trek-router
  • express (ハンドリングを含む)
  • koa-router

まず、各ルーターに以下のルーティングを登録しました。これらは実際の使用状況に類似しています。

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

次に、以下のようにエンドポイントにリクエストを送信しました。

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

結果を見てみましょう。

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向けの他のルーターと比較して。

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 'https://#: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で最速のフレームワークの1つです。以下をご覧ください。

MITライセンスでリリースされています。