diff --git a/benchmark/utils.mjs b/benchmark/utils.mjs index a9a5e54..a6d6f26 100644 --- a/benchmark/utils.mjs +++ b/benchmark/utils.mjs @@ -3,11 +3,15 @@ import { readFileSync } from "node:fs"; import os from "node:os"; import { createRouter } from "radix3"; -export const logSection = (title) => { console.log(`\n--- ${title} ---\n`); }; +export const logSection = (title) => { + console.log(`\n--- ${title} ---\n`); +}; -const pkgVersion = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version; +const pkgVersion = JSON.parse( + readFileSync(new URL("../package.json", import.meta.url), "utf8") +).version; -export function printEnv () { +export function printEnv() { logSection("Test environment"); console.log("Node.js version:", process.versions.node); console.log("Radix3 version:", pkgVersion); @@ -17,36 +21,46 @@ export function printEnv () { console.log(""); } -export function printStats (stats) { - console.log("Stats:\n" + Object.entries(stats).map(([path, hits]) => ` - ${path}: ${hits}`).join("\n")); +export function printStats(stats) { + console.log( + "Stats:\n" + + Object.entries(stats) + .map(([path, hits]) => ` - ${path}: ${hits}`) + .join("\n") + ); } export const router = createRouter({ - routes: Object.fromEntries([ - "/hello", - "/cool", - "/hi", - "/helium", - "/coooool", - "/chrome", - "/choot", - "/choot/:choo", - "/ui/**", - "/ui/components/**" - ].map(path => [path, { path }])) + routes: Object.fromEntries( + [ + "/hello", + "/cool", + "/hi", + "/helium", + "/coooool", + "/chrome", + "/choot", + "/choot/:choo", + "/ui/**", + "/ui/components/**", + ].map((path) => [path, { path }]) + ), }); +router.insert("/method-get", { path: "/method-get" }, { method: "GET" }); +router.insert("/method-post", { path: "/method-get" }, { method: "POST" }); + export const benchSets = [ { title: "static route", - requests: [ - { path: "/choot" } - ] + requests: [{ path: "/choot" }], }, { title: "dynamic route", - requests: [ - { path: "/choot/123" } - ] - } + requests: [{ path: "/choot/123" }], + }, + { + title: "method route", + requests: [{ path: "/method-get", method: "GET" }], + }, ];