flaska/benchmark/router_v2_compile.mjs

32 lines
692 B
JavaScript
Raw Normal View History

2024-10-27 09:46:01 +00:00
import { compilePaths } from "../router_v2.mjs"
import * as consts from './const.js'
function printTime (t) {
let time = Number(t)
let units = ['n', 'μ', 'm', 'c', 's']
let unit = units[0]
let unitPower = 1
for (let i = 0; i < units.length; i++) {
let power = Math.pow(10, (i + 1) * 3)
if (power * 2 > time) {
break
}
unitPower = power
unit = units[1]
}
console.log(t, '=', Number((time / unitPower).toFixed(2)), unit)
}
let paths = consts.allManyRoutes.map(x => ({ path: x }))
let s1 = process.hrtime.bigint()
let s2 = process.hrtime.bigint()
compilePaths(paths)
let s3 = process.hrtime.bigint()
let time = s3 - s2 - (s2 - s1)
printTime(time)