flexrouter implement in koa
Compared to koa-router, find-my-way, it has a similar performance result when there're 50 routes. When increase route to 2401, the performance result:
codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js
benchmark home path: '/', and a random path: '/cndhomeainrmsfbn/1/wxcfkdikzb'
koa-router#topic-detail x 944 ops/sec ±122.08% (93 runs sampled)
find-my-way#topic-detail x 1,079,235 ops/sec ±6.18% (87 runs sampled)
flexrouter#topic-detail x 2,887,212 ops/sec ±1.10% (93 runs sampled)
codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js
benchmark home path: '/', and a random path: '/nblqjipdz/1/'
koa-router#topic-detail x 959 ops/sec ±121.41% (94 runs sampled)
find-my-way#topic-detail x 1,847,886 ops/sec ±1.22% (96 runs sampled)
flexrouter#topic-detail x 4,112,523 ops/sec ±1.21% (89 runs sampled)
codespace ➜ /workspaces/koa-flexrouter/benchmark (master ✗) $ node index.js
benchmark home path: '/', and a random path: '/xeyk/1/avdegacnmiesgk'
koa-router#topic-detail x 977 ops/sec ±119.90% (92 runs sampled)
find-my-way#topic-detail x 1,343,876 ops/sec ±0.66% (94 runs sampled)
flexrouter#topic-detail x 2,550,022 ops/sec ±0.92% (93 runs sampled)
npm i koa-flexrouter
import Router from 'koa-flexrouter';
import * as Koa from 'koa';
const router = new Router();
const app = new Koa();
router.get('/test', async (ctx, next) => {
})
router.post('/test', async (ctx, next) => {
})
app.use(router.routes())
import Router from 'koa-flexrouter';
import * as Koa from 'koa';
const router = new Router();
const app = new Koa();
const subRouter = router.group({
path: '/sub',
middlewares: [
async (ctx, next) => {
return next();
},
async (ctx, next) => {
return next();
},
]
})
subRouter.get('/:id/xxx', async (ctx, next) => {
})
subRouter.post('/:id/*action', async (ctx, next) => {
})
app.use(router.routes())