generated from yamiteru/ts-package
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.DS_Store | ||
.code | ||
.idea | ||
.obsidian | ||
|
||
node_modules | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |