Skip to content

Commit 3698fc1

Browse files
committed
src: add bench-node support and use by default
1 parent a5d4da2 commit 3698fc1

14 files changed

+148
-96
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ bench-it ./node
4747
To a pretty terminal output, run `index.js`
4848

4949
```console
50-
$ node index.js
50+
$ node --allow-natives-syntax index.js
5151
cpu: 13th Gen Intel(R) Core(TM) i5-13600K (20 cores)
5252
node: v20.13.1 (/home/hzk/.nvm/versions/node/v20.13.1/bin/node)
5353
os: Linux 5.15.133.1-microsoft-standard-WSL2 x64

bench-it.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (process.argv.length < 3) {
1313
const BINARY = process.argv[2];
1414

1515
if (process.argv[3] === "baseline") {
16-
const result = execSync(`${BINARY} ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
16+
const result = execSync(`${BINARY} --allow-natives-syntax ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
1717
env: { TTY: true },
1818
}).toString();
1919
fs.writeFileSync('baseline.out', `${result}`);
@@ -34,7 +34,7 @@ try {
3434
diffCmd = "diff";
3535
}
3636

37-
const currentResult = execSync(`${BINARY} ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
37+
const currentResult = execSync(`${BINARY} --allow-natives-syntax ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
3838
env: { TTY: true },
3939
}).toString();
4040
fs.writeFileSync('current.out', currentResult);

index.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node --allow-natives-syntax
22

33
const fs = require('node:fs/promises');
44
const path = require('node:path');

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@types/lodash": "4.17.3",
3131
"@types/underscore": "1.11.15",
3232
"autocannon": "7.15.0",
33+
"bench-node": "0.1.0",
3334
"dotenv": "16.4.5",
3435
"fastify": "4.26.1",
3536
"lodash": "4.17.21",

src/babel-benchmark.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('node:fs');
22
const path = require('node:path');
3+
const assert = require('node:assert');
34
const Babel = require('@babel/standalone');
45

56
const payloads = [
@@ -16,6 +17,7 @@ module.exports = {
1617
let v = undefined;
1718
for (const p of payloads) {
1819
v = Babel.transform(p, { code: true, ast: true }).code;
20+
assert.ok(v)
1921
}
2022
return v;
2123
},
@@ -25,7 +27,8 @@ module.exports = {
2527
fn: () => {
2628
let v = undefined;
2729
for (const p of payloads) {
28-
v = Babel.transform(p, { code: false }).code;
30+
v = Babel.transform(p, { code: false });
31+
assert.ok(v);
2932
}
3033
return v;
3134
},

src/dotenv-benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ module.exports = {
1414
},
1515
},
1616
],
17-
benchmarker: 'tinybench',
17+
benchmarker: 'bench-node',
1818
};

src/lodash-benchmark.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('node:assert');
12
const lodash = require('lodash');
23

34
module.exports = {
@@ -7,19 +8,19 @@ module.exports = {
78
{
89
name: '.chunk',
910
fn: () => {
10-
lodash.chunk(['a', 'b', 'c', 'd'], 2);
11+
assert.ok(lodash.chunk(['a', 'b', 'c', 'd'], 2));
1112
},
1213
},
1314
{
1415
name: '.groupBy',
1516
fn: () => {
16-
lodash.groupBy([6.1, 4.2, 6.3], Math.floor);
17+
assert.ok(lodash.groupBy([6.1, 4.2, 6.3], Math.floor));
1718
},
1819
},
1920
{
2021
name: '.includes',
2122
fn: () => {
22-
lodash.includes({ 'a': 1, 'b': 2 }, 1);
23+
assert.ok(lodash.includes({ 'a': 1, 'b': 2 }, 1));
2324
},
2425
},
2526
{
@@ -31,9 +32,9 @@ module.exports = {
3132
{ 'user': 'fred', 'age': 40 },
3233
{ 'user': 'barney', 'age': 36 }
3334
];
34-
lodash.orderBy(users, ['user', 'age'], ['asc', 'desc']);
35+
assert.ok(lodash.orderBy(users, ['user', 'age'], ['asc', 'desc']));
3536
}
3637
}
3738
],
38-
benchmarker: 'tinybench',
39+
benchmarker: 'bench-node',
3940
};

src/moment-benchmark.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const assert = require('node:assert');
12
const moment = require('moment');
23

34
module.exports = {
@@ -7,27 +8,27 @@ module.exports = {
78
{
89
name: 'format (full)',
910
fn: () => {
10-
return moment().format('MMMM Do YYYY, h:mm:ss a');
11+
assert.ok(moment().format('MMMM Do YYYY, h:mm:ss a'));
1112
},
1213
},
1314
{
1415
name: 'format',
1516
fn: () => {
16-
return moment().format();
17+
assert.ok(moment().format());
1718
},
1819
},
1920
{
2021
name: 'fromNow (YYYYMMDD)',
2122
fn: () => {
22-
return moment('20111031', 'YYYYMMDD').fromNow();
23+
assert.ok(moment('20111031', 'YYYYMMDD').fromNow());
2324
},
2425
},
2526
{
2627
name: 'subtract (10)',
2728
fn: () => {
28-
return moment().subtract(10, 'days').calendar();
29+
assert.ok(moment().subtract(10, 'days').calendar());
2930
},
3031
},
3132
],
32-
benchmarker: 'tinybench',
33+
benchmarker: 'bench-node',
3334
};

src/pino-benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ module.exports = {
1414
},
1515
},
1616
],
17-
benchmarker: 'tinybench',
17+
benchmarker: 'bench-node',
1818
};

src/prettier-benchmark.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('node:fs');
22
const path = require('node:path');
3+
const assert = require('node:assert');
34
const prettier = require('prettier');
45

56
const payloads = [
@@ -15,7 +16,8 @@ module.exports = {
1516
fn: () => {
1617
let v = undefined;
1718
for (const p of payloads) {
18-
v= prettier.format(p, { parser: 'babel' });
19+
v = prettier.format(p, { parser: 'babel' });
20+
assert.ok(v);
1921
}
2022
return v;
2123
},
@@ -29,6 +31,7 @@ module.exports = {
2931
p,
3032
{ singleQuote: true, useTabs: true, parser: 'babel' },
3133
);
34+
assert.ok(v);
3235
}
3336
return v;
3437
},
@@ -42,6 +45,7 @@ module.exports = {
4245
p,
4346
{ semi: false, parser: 'babel' }
4447
);
48+
assert.ok(v);
4549
}
4650
return v;
4751
},

0 commit comments

Comments
 (0)