Skip to content

Commit

Permalink
feat: use chartReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Oct 21, 2024
1 parent 4a90b4b commit 28f9e35
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions common.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Suite } from 'bench-node'
import { Suite, chartReport } from 'bench-node'
import { createTableHeader, H2, taskToMdTable } from './markdown.mjs'
import { platform, arch, cpus, totalmem } from 'os'

Expand Down Expand Up @@ -71,13 +71,15 @@ function printMarkdownHiddenDetailedInfo(results) {
}

Suite.prototype.runAndPrintResults = async function () {
const results = await this.run()
printMarkdownResults(results)
console.log('```')
await this.run()
console.log('```')
// printMarkdownResults(results)
}

export function createBenchmarkSuite(name, { tableHeaderColumns = ['name', 'ops/sec', 'samples'] } = {}) {
const suite = new Suite({ reporter: false })
const suite = new Suite({ reporter: chartReport })
// TODO: move it to runAndPrintResults
printMdHeader(name, tableHeaderColumns)
printMdHeader(name, [])
return suite
}
3 changes: 3 additions & 0 deletions markdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export function taskToMdTable (result) {
}

export function createTableHeader(columns) {
if (!columns.length) {
return '';
}
let header = '|'
let headerSep = '|'
for (const col of columns) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "bin.js",
"dependencies": {
"autocannon": "^7.7.1",
"bench-node": "^0.0.4-beta.3",
"bench-node": "^0.2.0",
"benchmark": "^2.1.4",
"fastify": "^4.4.0",
"on-net-listen": "^1.1.2",
Expand Down

0 comments on commit 28f9e35

Please sign in to comment.