Skip to content

Commit

Permalink
build: use bench-node over tinybench (#256)
Browse files Browse the repository at this point in the history
* build: use bench-node over tinybench

* fixup! build: use bench-node over tinybench

* chore: add benchmark results from bench-node

chore(add-property.mjs): update benchmark results

chore(array-append.mjs): update benchmark results

chore(array-creation.mjs): update benchmark results

chore(compare-using-instanceof.mjs): update benchmark results

chore(crypto-verify.mjs): update benchmark results

chore(date-format-iso.mjs): update benchmark results

chore(date-format.mjs): update benchmark results

chore(date-string-coersion.mjs): update benchmark results

chore(deleting-properties.mjs): update benchmark results

chore(error.mjs): update benchmark results

chore(function-return.mjs): update benchmark results

chore(includes-vs-raw-comparison.mjs): update benchmark results

chore(keys-vs-getownpropertynames.mjs): update benchmark results

chore(last-array-item.mjs): update benchmark results

chore(math-floor-vs-tilde.mjs): update benchmark results

chore(object-creation.mjs): update benchmark results

chore(optional-chain-vs-and-operator.mjs): update benchmark results

chore(parse-int.mjs): update benchmark results

chore(possible-undefined-function.mjs): update benchmark results

chore(private-property.mjs): update benchmark results

chore(property-access-transition.mjs): update benchmark results

chore(property-getter-access.mjs): update benchmark results

chore(property-setter-access.mjs): update benchmark results

chore(replace-vs-replaceall-comparison.mjs): update benchmark results

chore(shallow-copy.mjs): update benchmark results

chore(sort-map.mjs): update benchmark results

chore(spread-vs-object-assign.mjs): update benchmark results

chore(stream-readable.mjs): update benchmark results

chore(stream-writable.mjs): update benchmark results

chore(string-concat.mjs): update benchmark results

chore(string-endsWith.mjs): update benchmark results

chore(string-searching.mjs): update benchmark results

chore(string-startsWith.mjs): update benchmark results

chore(super-vs-this.mjs): update benchmark results

chore(unix-time.mjs): update benchmark results

---------

Co-authored-by: Github Actions <[email protected]>
  • Loading branch information
RafaelGSS and actions-user authored Oct 8, 2024
1 parent 618560e commit c629ff6
Show file tree
Hide file tree
Showing 113 changed files with 1,998 additions and 1,806 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
run: echo "BENCH_REPORT_FILE=report-${{github.run_id}}-${{ matrix.node-version }}-${{ inputs.bench-file }}.md" >> $GITHUB_ENV

- name: Run Benchmark
run: node ${{ inputs.node-opts }} bench/${{ inputs.bench-file }} > ./${{ env.BENCH_REPORT_FILE }}
run: node --allow-natives-syntax ${{ inputs.node-opts }} bench/${{ inputs.bench-file }} > ./${{ env.BENCH_REPORT_FILE }}
env:
CI: true

Expand Down
539 changes: 289 additions & 250 deletions RESULTS-v22.md

Large diffs are not rendered by default.

52 changes: 14 additions & 38 deletions common.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bench } from 'tinybench'
import { Suite } from 'bench-node'
import { createTableHeader, H2, taskToMdTable } from './markdown.mjs'
import { platform, arch, cpus, totalmem } from 'os'

Expand All @@ -8,19 +8,19 @@ function printMdHeader(name, tableHeaderColumns = ['name', 'ops/sec', 'samples']
console.log(tableHeader)
}

function printMarkdownResults(tasks) {
function printMarkdownResults(results) {
const cycleEvents = []
for (const task of tasks) {
for (const r of results) {
if (process.env.CI) {
cycleEvents.push({
name: task.name,
opsSec: task.result.hz,
samples: task.result.samples.length,
name: r.name,
opsSec: r.opsSec,
samples: r.iterations,
})
}
console.log(taskToMdTable(task))
console.log(taskToMdTable(r))
}
printMarkdownMachineInfo(cycleEvents)
printMarkdownMachineInfo()
printMarkdownHiddenDetailedInfo(cycleEvents)
}

Expand Down Expand Up @@ -53,7 +53,7 @@ function printMarkdownMachineInfo() {
writter.write('\n\n')
}

function printMarkdownHiddenDetailedInfo(cycleEvents) {
function printMarkdownHiddenDetailedInfo(results) {
if (!process.env.CI) return

const writter = process.stdout
Expand All @@ -63,44 +63,20 @@ function printMarkdownHiddenDetailedInfo(cycleEvents) {
writter.write(
JSON.stringify({
environment: getMachineInfo(),
benchmarks: cycleEvents,
benchmarks: results,
}),
)
writter.write('-->\n')
}

Bench.prototype.runAndPrintResults = async function () {
await this.warmup()
await this.run()
printMarkdownResults(this.tasks)
Suite.prototype.runAndPrintResults = async function () {
const results = await this.run()
printMarkdownResults(results)
}

export function createBenchmarkSuite(name, { tableHeaderColumns = ['name', 'ops/sec', 'samples'] } = {}) {
const suite = new Bench({ warmupTime: 1000 })
const suite = new Suite({ reporter: false })
// TODO: move it to runAndPrintResults
printMdHeader(name, tableHeaderColumns)
return suite
}

// ➜ nodejs-bench-operations (main) node bench/add-property.mjs
// ## Adding property

// |name|ops/sec|samples|
// |-|-|-|
// |Directly in the object|18,428,648|9214325|
// |Using dot notation|17,217,733|8608867|
// |Using define property (writable)|3,052,726|1526364|
// |Using define property initialized (writable)|3,651,585|1825856|
// |Using define property (getter)|1,765,147|882574|
// ➜ nodejs-bench-operations (main) nvm use v22
// Now using node v22.7.0 (npm v10.8.2)
// ➜ nodejs-bench-operations (main) node bench/add-property.mjs
// ## Adding property

// |name|ops/sec|samples|
// |-|-|-|
// |Directly in the object|15,205,217|7602609|
// |Using dot notation|15,432,921|7716461|
// |Using define property (writable)|3,243,836|1621919|
// |Using define property initialized (writable)|3,557,399|1778700|
// |Using define property (getter)|2,047,757|1023879|
5 changes: 2 additions & 3 deletions markdown.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export function taskToMdTable (task) {
const { result } = task
return `|${task.name}|${parseInt(result.hz.toString(), 10).toLocaleString()}|${result.samples.length}|`
export function taskToMdTable (result) {
return `|${result.name}|${parseInt(result.opsSec.toString(), 10).toLocaleString()}|${result.iterations}|`
}

export function createTableHeader(columns) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "bin.js",
"dependencies": {
"autocannon": "^7.7.1",
"bench-node": "^0.0.4-beta.3",
"benchmark": "^2.1.4",
"fastify": "^4.4.0",
"on-net-listen": "^1.1.2",
"privsym": "^1.0.0",
"semver": "^7.5.4",
"tinybench": "^2.8.0"
"semver": "^7.5.4"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
522 changes: 261 additions & 261 deletions v22/RESULTS-v22_0_0.md

Large diffs are not rendered by default.

Loading

0 comments on commit c629ff6

Please sign in to comment.