Skip to content

Commit

Permalink
chore: output benchmark results to tmp/benchmark (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a committed Oct 21, 2023
1 parent 7df2502 commit d235d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
7 changes: 5 additions & 2 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ export function run({
await client.flushdb();
}),
save({
file: `${driver}-bench`,
file: driver,
details: true,
folder: join(dirname(dirname(new URL(import.meta.url).pathname)), "tmp"),
folder: join(
dirname(dirname(new URL(import.meta.url).pathname)),
"tmp/benchmark",
),
}),
);
}
17 changes: 10 additions & 7 deletions tools/format-benchmark-results.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from "node:path";

function formatResultsAsMarkdown({ name, results }) {
const detailKeys = ["min", "max", "mean", "median"];
const header = ["name", "ops", "margin", ...detailKeys, "samples"];
Expand Down Expand Up @@ -25,11 +27,12 @@ function makeTableRow(columns) {
return `|${columns.join("|")}|`;
}

const tmpDir = new URL("../tmp", import.meta.url).pathname;
for (const driver of ["deno-redis", "ioredis"]) {
console.log(
formatResultsAsMarkdown(
JSON.parse(await Deno.readTextFile(`${tmpDir}/${driver}-bench.json`)),
),
);
const resultsDir = new URL("../tmp/benchmark", import.meta.url);
const paths = Array.from(Deno.readDirSync(resultsDir)).map((x) =>
join(resultsDir.pathname, x.name)
).sort();
for (const path of paths) {
const results = JSON.parse(await Deno.readTextFile(path));
const markdown = formatResultsAsMarkdown(results);
console.log(markdown);
}

0 comments on commit d235d71

Please sign in to comment.