Skip to content

Commit

Permalink
feat: add method benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Hebilicious committed Jul 30, 2023
1 parent a4e3655 commit 0b7074e
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions benchmark/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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" }],
},
];

0 comments on commit 0b7074e

Please sign in to comment.