File tree Expand file tree Collapse file tree 4 files changed +107
-4
lines changed Expand file tree Collapse file tree 4 files changed +107
-4
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,33 @@ packages operations.
1515- [x] winston
1616- [x] underscore
1717
18- ## Running
18+ ## Install
19+
20+ ``` console
21+ npm i -g nodejs-package-benchmark
22+ ```
23+
24+ ## Comparison
25+
26+ To compare binaries, you can use the ` bench-it ` script.
27+
28+ ### Syntax: ` bench-it $BINARY ["baseline"] `
29+
30+ This script allows you to compare the performance of binaries. If it's your first run, you need to generate the ` baseline ` data using:
31+
32+ ``` console
33+ $ bench-it ./node baseline
34+ ```
35+
36+ To compare subsequent runs, simply omit the "baseline" option:
37+
38+ ``` console
39+ $ bench-it ./node
40+ ```
41+
42+ > ** Note:** It's recommended to have ` colordiff ` installed for a clearer comparison of differences.
43+
44+ ## Single run
1945
2046To a pretty terminal output, run ` index.js `
2147
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ const { execSync } = require ( 'child_process' ) ;
4+ const fs = require ( 'fs' ) ;
5+
6+ const NODEJS_PACKAGE_BENCHMARK_PATH = __dirname ;
7+
8+ if ( process . argv . length < 3 ) {
9+ console . log ( "You must pass the binary as argument. Example: bench-it ./node" ) ;
10+ process . exit ( 1 ) ;
11+ }
12+
13+ const BINARY = process . argv [ 2 ] ;
14+
15+ if ( process . argv [ 3 ] === "baseline" ) {
16+ const baseline = execSync ( 'git rev-parse HEAD' ) . toString ( ) . trim ( ) ;
17+ const result = execSync ( `${ BINARY } ${ NODEJS_PACKAGE_BENCHMARK_PATH } /index.js` , {
18+ env : { TTY : true } ,
19+ } ) . toString ( ) ;
20+ fs . writeFileSync ( 'baseline.out' , `${ baseline } \n${ result } ` ) ;
21+ console . log ( "Baseline generated." ) ;
22+ process . exit ( 0 ) ;
23+ }
24+
25+ if ( ! fs . existsSync ( './baseline.out' ) ) {
26+ console . log ( `The baseline.out does not exist. Generate it with: $ bench-it ${ BINARY } baseline.` ) ;
27+ process . exit ( 1 ) ;
28+ }
29+
30+ let diffCmd = "colordiff" ;
31+ try {
32+ execSync ( "command -v colordiff" ) ;
33+ } catch ( error ) {
34+ console . log ( "⚠️ 'colordiff' was not found. Using 'diff' as fallback." ) ;
35+ diffCmd = "diff" ;
36+ }
37+
38+ const currentResult = execSync ( `${ BINARY } ${ NODEJS_PACKAGE_BENCHMARK_PATH } /index.js` , {
39+ env : { TTY : true } ,
40+ } ) . toString ( ) ;
41+ fs . writeFileSync ( 'current.out' , currentResult ) ;
42+
43+ try {
44+ const stdout = execSync ( `${ diffCmd } -y baseline.out current.out` , {
45+ cwd : process . cwd ( )
46+ } )
47+ console . log ( stdout . toString ( ) )
48+ } catch ( e ) {
49+ // `diff` returns a non-0 exit code
50+ console . log ( e . message )
51+ console . log ( e . stdout . toString ( ) )
52+ }
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
13const fs = require ( 'node:fs/promises' ) ;
24const path = require ( 'node:path' ) ;
35const Piscina = require ( 'piscina' ) ;
Original file line number Diff line number Diff line change 11{
2+ "name" : " nodejs-package-benchmark" ,
3+ "description" : " This package allows you to benchmark different runtimes using popular packages operations." ,
4+ "version" : " 1.0.0-beta.1" ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " echo \" Error: no test specified\" && exit 1"
8+ },
9+ "repository" : {
10+ "type" : " git" ,
11+ "url" : " git+https://github.com/NodeSource/nodejs-package-benchmark.git"
12+ },
13+ "keywords" : [
14+ " benchmark" ,
15+ " nodejs" ,
16+ " core"
17+ ],
18+ "author" :
" RafaelGSS <[email protected] >" ,
19+ "license" : " MIT" ,
20+ "bugs" : {
21+ "url" : " https://github.com/NodeSource/nodejs-package-benchmark/issues"
22+ },
23+ "homepage" : " https://github.com/NodeSource/nodejs-package-benchmark#readme" ,
24+ "bin" : {
25+ "bench-it" : " ./bench-it.js"
26+ },
227 "dependencies" : {
328 "@babel/standalone" : " 7.24.0" ,
429 "dotenv" : " 16.4.5" ,
934 "piscina" : " 4.4.0" ,
1035 "prettier" : " 3.2.5" ,
1136 "underscore" : " 1.13.6" ,
12- "winston" : " 3.12.0"
13- },
14- "devDependencies" : {
37+ "winston" : " 3.12.0" ,
1538 "autocannon" : " 7.15.0" ,
1639 "benchmark" : " 2.1.4"
1740 }
You can’t perform that action at this time.
0 commit comments