Skip to content

Commit c629ff6

Browse files
build: use bench-node over tinybench (#256)
* 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]>
1 parent 618560e commit c629ff6

File tree

113 files changed

+1998
-1806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1998
-1806
lines changed

.github/workflows/bench.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
run: echo "BENCH_REPORT_FILE=report-${{github.run_id}}-${{ matrix.node-version }}-${{ inputs.bench-file }}.md" >> $GITHUB_ENV
9090

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

RESULTS-v22.md

Lines changed: 289 additions & 250 deletions
Large diffs are not rendered by default.

common.mjs

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bench } from 'tinybench'
1+
import { Suite } from 'bench-node'
22
import { createTableHeader, H2, taskToMdTable } from './markdown.mjs'
33
import { platform, arch, cpus, totalmem } from 'os'
44

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

11-
function printMarkdownResults(tasks) {
11+
function printMarkdownResults(results) {
1212
const cycleEvents = []
13-
for (const task of tasks) {
13+
for (const r of results) {
1414
if (process.env.CI) {
1515
cycleEvents.push({
16-
name: task.name,
17-
opsSec: task.result.hz,
18-
samples: task.result.samples.length,
16+
name: r.name,
17+
opsSec: r.opsSec,
18+
samples: r.iterations,
1919
})
2020
}
21-
console.log(taskToMdTable(task))
21+
console.log(taskToMdTable(r))
2222
}
23-
printMarkdownMachineInfo(cycleEvents)
23+
printMarkdownMachineInfo()
2424
printMarkdownHiddenDetailedInfo(cycleEvents)
2525
}
2626

@@ -53,7 +53,7 @@ function printMarkdownMachineInfo() {
5353
writter.write('\n\n')
5454
}
5555

56-
function printMarkdownHiddenDetailedInfo(cycleEvents) {
56+
function printMarkdownHiddenDetailedInfo(results) {
5757
if (!process.env.CI) return
5858

5959
const writter = process.stdout
@@ -63,44 +63,20 @@ function printMarkdownHiddenDetailedInfo(cycleEvents) {
6363
writter.write(
6464
JSON.stringify({
6565
environment: getMachineInfo(),
66-
benchmarks: cycleEvents,
66+
benchmarks: results,
6767
}),
6868
)
6969
writter.write('-->\n')
7070
}
7171

72-
Bench.prototype.runAndPrintResults = async function () {
73-
await this.warmup()
74-
await this.run()
75-
printMarkdownResults(this.tasks)
72+
Suite.prototype.runAndPrintResults = async function () {
73+
const results = await this.run()
74+
printMarkdownResults(results)
7675
}
7776

7877
export function createBenchmarkSuite(name, { tableHeaderColumns = ['name', 'ops/sec', 'samples'] } = {}) {
79-
const suite = new Bench({ warmupTime: 1000 })
78+
const suite = new Suite({ reporter: false })
8079
// TODO: move it to runAndPrintResults
8180
printMdHeader(name, tableHeaderColumns)
8281
return suite
8382
}
84-
85-
// ➜ nodejs-bench-operations (main) node bench/add-property.mjs
86-
// ## Adding property
87-
88-
// |name|ops/sec|samples|
89-
// |-|-|-|
90-
// |Directly in the object|18,428,648|9214325|
91-
// |Using dot notation|17,217,733|8608867|
92-
// |Using define property (writable)|3,052,726|1526364|
93-
// |Using define property initialized (writable)|3,651,585|1825856|
94-
// |Using define property (getter)|1,765,147|882574|
95-
// ➜ nodejs-bench-operations (main) nvm use v22
96-
// Now using node v22.7.0 (npm v10.8.2)
97-
// ➜ nodejs-bench-operations (main) node bench/add-property.mjs
98-
// ## Adding property
99-
100-
// |name|ops/sec|samples|
101-
// |-|-|-|
102-
// |Directly in the object|15,205,217|7602609|
103-
// |Using dot notation|15,432,921|7716461|
104-
// |Using define property (writable)|3,243,836|1621919|
105-
// |Using define property initialized (writable)|3,557,399|1778700|
106-
// |Using define property (getter)|2,047,757|1023879|

markdown.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
export function taskToMdTable (task) {
2-
const { result } = task
3-
return `|${task.name}|${parseInt(result.hz.toString(), 10).toLocaleString()}|${result.samples.length}|`
1+
export function taskToMdTable (result) {
2+
return `|${result.name}|${parseInt(result.opsSec.toString(), 10).toLocaleString()}|${result.iterations}|`
43
}
54

65
export function createTableHeader(columns) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"main": "bin.js",
66
"dependencies": {
77
"autocannon": "^7.7.1",
8+
"bench-node": "^0.0.4-beta.3",
89
"benchmark": "^2.1.4",
910
"fastify": "^4.4.0",
1011
"on-net-listen": "^1.1.2",
1112
"privsym": "^1.0.0",
12-
"semver": "^7.5.4",
13-
"tinybench": "^2.8.0"
13+
"semver": "^7.5.4"
1414
},
1515
"scripts": {
1616
"test": "echo \"Error: no test specified\" && exit 1"

v22/RESULTS-v22_0_0.md

Lines changed: 261 additions & 261 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)