flaska/benchmark/mapl_router_compile.mjs

32 lines
728 B
JavaScript
Raw Normal View History

2024-11-02 12:44:54 +00:00
import { createRouter, insertItem } from '@mapl/router'
import { compileRouter } from './mapl_compiler.mjs'
import { printTime } from './utils.mjs'
import * as consts from './const.js'
let testPaths = consts.allManyRoutes // consts.allManyRoutes
/*testPaths = [
'/api/works/:id/lock',
'/api/staff/:id',
// '/::rest',
]*/
testPaths = testPaths.map(x => x.replace(/::[^\/]+/g, '**').replace(/:[^\/]+/g, '*'))
const r = createRouter();
for (let route of testPaths) {
let cleaned = route.replace(/:[^\/]+/g, '*')
insertItem(r, cleaned, () => { })
}
let s1 = process.hrtime.bigint()
let s2 = process.hrtime.bigint()
compileRouter(r);
let s3 = process.hrtime.bigint()
let time = s3 - s2 - (s2 - s1)
printTime(time)