Skip to content

Commit

Permalink
Render to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiteru committed Mar 4, 2023
1 parent 1521e0c commit c257bf5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.code
.idea
.obsidian

node_modules
dist
Expand Down
4 changes: 4 additions & 0 deletions result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| name | op/s | kbs |
|---|---|---|
| emptySync | 1 000 000 000 | 0 |
| test | 17 241 379 | 13 144 |
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { outputToMarkdown } from "./output/outputToMarkdown";
import { preset } from "./preset";
import { printSuite } from "./printSuite";

const defaultSuite = preset();
const callibration = defaultSuite({
Expand All @@ -12,5 +12,5 @@ const callibration = defaultSuite({
});

(async () => {
await printSuite(callibration);
await outputToMarkdown(callibration, "./result.md");
})();
54 changes: 54 additions & 0 deletions src/output/outputToMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { writeFile } from "fs/promises";
import { Fn, Results } from "../types";

export async function outputToMarkdown(
suite: Fn<[], AsyncGenerator<Results>>,
path: string
) {
const results: Results[] = [];

let longestName = 0;
let mostKbs = 0;

console.log("Benchmark started");

for await (const result of suite()) {
console.log(`-${result.name}`);

if(result.name.length > longestName) {
longestName = result.name.length;
}

if(result.ram.median > mostKbs) {
mostKbs = result.ram.median;
}

results.push(result);
}

console.log("Benchmark ended");

const sorted = results.sort(
({ cpu: { median: a } }, { cpu: { median: b } }) => a - b,
);

let markdown = "";

markdown += `| name | op/s | kbs |\n`;
markdown += `|---|---|---|\n`;

for(let i = 0; i < results.length; ++i) {
const result = sorted[i];

const ops =
result.cpu.median === 0
? 1_000_000_000
: Math.round(1_000_000_000 / result.cpu.median);

markdown += `| ${result.name} | ${ops.toLocaleString("en").replaceAll(",", " ")} | ${result.ram.median.toLocaleString("en").replaceAll(",", " ")} |\n`;
}

await writeFile(path, markdown);

console.log(`Results saved to ${path}`);
}

0 comments on commit c257bf5

Please sign in to comment.