1
- import { Bench } from 'tinybench '
1
+ import { Suite } from 'bench-node '
2
2
import { createTableHeader , H2 , taskToMdTable } from './markdown.mjs'
3
3
import { platform , arch , cpus , totalmem } from 'os'
4
4
@@ -8,19 +8,19 @@ function printMdHeader(name, tableHeaderColumns = ['name', 'ops/sec', 'samples']
8
8
console . log ( tableHeader )
9
9
}
10
10
11
- function printMarkdownResults ( tasks ) {
11
+ function printMarkdownResults ( results ) {
12
12
const cycleEvents = [ ]
13
- for ( const task of tasks ) {
13
+ for ( const r of results ) {
14
14
if ( process . env . CI ) {
15
15
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 ,
19
19
} )
20
20
}
21
- console . log ( taskToMdTable ( task ) )
21
+ console . log ( taskToMdTable ( r ) )
22
22
}
23
- printMarkdownMachineInfo ( cycleEvents )
23
+ printMarkdownMachineInfo ( )
24
24
printMarkdownHiddenDetailedInfo ( cycleEvents )
25
25
}
26
26
@@ -53,7 +53,7 @@ function printMarkdownMachineInfo() {
53
53
writter . write ( '\n\n' )
54
54
}
55
55
56
- function printMarkdownHiddenDetailedInfo ( cycleEvents ) {
56
+ function printMarkdownHiddenDetailedInfo ( results ) {
57
57
if ( ! process . env . CI ) return
58
58
59
59
const writter = process . stdout
@@ -63,44 +63,20 @@ function printMarkdownHiddenDetailedInfo(cycleEvents) {
63
63
writter . write (
64
64
JSON . stringify ( {
65
65
environment : getMachineInfo ( ) ,
66
- benchmarks : cycleEvents ,
66
+ benchmarks : results ,
67
67
} ) ,
68
68
)
69
69
writter . write ( '-->\n' )
70
70
}
71
71
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 )
76
75
}
77
76
78
77
export function createBenchmarkSuite ( name , { tableHeaderColumns = [ 'name' , 'ops/sec' , 'samples' ] } = { } ) {
79
- const suite = new Bench ( { warmupTime : 1000 } )
78
+ const suite = new Suite ( { reporter : false } )
80
79
// TODO: move it to runAndPrintResults
81
80
printMdHeader ( name , tableHeaderColumns )
82
81
return suite
83
82
}
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|
0 commit comments