-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathformat-benchmark-results.js
39 lines (36 loc) · 1.02 KB
/
format-benchmark-results.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { join } from "node:path";
function formatResultsAsMarkdown({ name, results }) {
const detailKeys = ["min", "max", "mean", "median"];
const header = ["name", "ops", "margin", ...detailKeys, "samples"];
const rows = results.map((result) => {
const { name, ops, margin, details, samples } = result;
return [
name,
ops,
margin,
...detailKeys.map((key) => details[key]),
samples,
];
});
const table = [
header,
header.map(() => ":---:"),
...rows,
]
.map(makeTableRow)
.join("\n");
return `## ${name}\n\n${table}\n`;
}
function makeTableRow(columns) {
return `|${columns.join("|")}|`;
}
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);
// deno-lint-ignore no-console
console.log(markdown);
}