Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ bench-it ./node
To a pretty terminal output, run `index.js`

```console
$ node index.js
$ node --allow-natives-syntax index.js
cpu: 13th Gen Intel(R) Core(TM) i5-13600K (20 cores)
node: v20.13.1 (/home/hzk/.nvm/versions/node/v20.13.1/bin/node)
os: Linux 5.15.133.1-microsoft-standard-WSL2 x64
Expand Down
4 changes: 2 additions & 2 deletions bench-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (process.argv.length < 3) {
const BINARY = process.argv[2];

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

const currentResult = execSync(`${BINARY} ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
const currentResult = execSync(`${BINARY} --allow-natives-syntax ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
env: { TTY: true },
}).toString();
fs.writeFileSync('current.out', currentResult);
Expand Down
2 changes: 1 addition & 1 deletion index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env node --allow-natives-syntax

const fs = require('node:fs/promises');
const path = require('node:path');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@types/lodash": "4.17.3",
"@types/underscore": "1.11.15",
"autocannon": "7.15.0",
"bench-node": "0.1.0",
"dotenv": "16.4.5",
"fastify": "4.26.1",
"lodash": "4.17.21",
Expand Down
5 changes: 4 additions & 1 deletion src/babel-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert');
const Babel = require('@babel/standalone');

const payloads = [
Expand All @@ -16,6 +17,7 @@ module.exports = {
let v = undefined;
for (const p of payloads) {
v = Babel.transform(p, { code: true, ast: true }).code;
assert.ok(v)
}
return v;
},
Expand All @@ -25,7 +27,8 @@ module.exports = {
fn: () => {
let v = undefined;
for (const p of payloads) {
v = Babel.transform(p, { code: false }).code;
v = Babel.transform(p, { code: false });
assert.ok(v);
}
return v;
},
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ module.exports = {
},
},
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
11 changes: 6 additions & 5 deletions src/lodash-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const assert = require('node:assert');
const lodash = require('lodash');

module.exports = {
Expand All @@ -7,19 +8,19 @@ module.exports = {
{
name: '.chunk',
fn: () => {
lodash.chunk(['a', 'b', 'c', 'd'], 2);
assert.ok(lodash.chunk(['a', 'b', 'c', 'd'], 2));
},
},
{
name: '.groupBy',
fn: () => {
lodash.groupBy([6.1, 4.2, 6.3], Math.floor);
assert.ok(lodash.groupBy([6.1, 4.2, 6.3], Math.floor));
},
},
{
name: '.includes',
fn: () => {
lodash.includes({ 'a': 1, 'b': 2 }, 1);
assert.ok(lodash.includes({ 'a': 1, 'b': 2 }, 1));
},
},
{
Expand All @@ -31,9 +32,9 @@ module.exports = {
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 36 }
];
lodash.orderBy(users, ['user', 'age'], ['asc', 'desc']);
assert.ok(lodash.orderBy(users, ['user', 'age'], ['asc', 'desc']));
}
}
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
11 changes: 6 additions & 5 deletions src/moment-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const assert = require('node:assert');
const moment = require('moment');

module.exports = {
Expand All @@ -7,27 +8,27 @@ module.exports = {
{
name: 'format (full)',
fn: () => {
return moment().format('MMMM Do YYYY, h:mm:ss a');
assert.ok(moment().format('MMMM Do YYYY, h:mm:ss a'));
},
},
{
name: 'format',
fn: () => {
return moment().format();
assert.ok(moment().format());
},
},
{
name: 'fromNow (YYYYMMDD)',
fn: () => {
return moment('20111031', 'YYYYMMDD').fromNow();
assert.ok(moment('20111031', 'YYYYMMDD').fromNow());
},
},
{
name: 'subtract (10)',
fn: () => {
return moment().subtract(10, 'days').calendar();
assert.ok(moment().subtract(10, 'days').calendar());
},
},
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
2 changes: 1 addition & 1 deletion src/pino-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ module.exports = {
},
},
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
6 changes: 5 additions & 1 deletion src/prettier-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert');
const prettier = require('prettier');

const payloads = [
Expand All @@ -15,7 +16,8 @@ module.exports = {
fn: () => {
let v = undefined;
for (const p of payloads) {
v= prettier.format(p, { parser: 'babel' });
v = prettier.format(p, { parser: 'babel' });
assert.ok(v);
}
return v;
},
Expand All @@ -29,6 +31,7 @@ module.exports = {
p,
{ singleQuote: true, useTabs: true, parser: 'babel' },
);
assert.ok(v);
}
return v;
},
Expand All @@ -42,6 +45,7 @@ module.exports = {
p,
{ semi: false, parser: 'babel' }
);
assert.ok(v);
}
return v;
},
Expand Down
145 changes: 74 additions & 71 deletions src/typescript-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,85 @@
const fs = require("node:fs");
const ts = require("typescript");
const path = require("node:path");
const fs = require('node:fs');
const ts = require('typescript');
const path = require('node:path');
const assert = require('node:assert');

const filePath = path.join(__dirname, "..", "fixtures", "ts-sample.ts");
const code = fs.readFileSync(filePath, "utf8");
const filePath = path.join(__dirname, '..', 'fixtures', 'ts-sample.ts');
const code = fs.readFileSync(filePath, 'utf8');

module.exports = {
name: "typescript",
type: "operation",
operations: [
{
name: "transpile",
fn: () => {
ts.transpile(
code,
{
// CJS Settings
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.Node,
name: 'typescript',
type: 'operation',
operations: [
{
name: 'transpile',
fn: () => {
const r = ts.transpile(
code,
{
// CJS Settings
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.Node,

// Avoid writing to disk
noEmit: true,
// Avoid writing to disk
noEmit: true,

// Avoids any checking related code
checkJs: false,
strict: false,
isolatedModules: true,
skipDefaultLibCheck: true,
skipLibCheck: true,
},
filePath,
);
},
},
{
name: "createSourceFile",
fn: () => {
ts.createSourceFile(
filePath,
code,
ts.ScriptTarget.ESNext,
false,
ts.ScriptKind.TS,
);
},
},
{
name: "getSemanticDiagnostics",
fn: () => {
const program = ts.createProgram({
rootNames: [filePath],
options: {
// CJS Settings
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.Node,
// Avoids any checking related code
checkJs: false,
strict: false,
isolatedModules: true,
skipDefaultLibCheck: true,
skipLibCheck: true,
},
filePath,
);
assert.ok(r);
},
},
{
name: 'createSourceFile',
fn: () => {
const r = ts.createSourceFile(
filePath,
code,
ts.ScriptTarget.ESNext,
false,
ts.ScriptKind.TS,
);
assert.ok(r);
},
},
{
name: 'getSemanticDiagnostics',
fn: () => {
const program = ts.createProgram({
rootNames: [filePath],
options: {
// CJS Settings
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.Node,

// also loads and checks js
allowJs: true,
checkJs: true,
// also loads and checks js
allowJs: true,
checkJs: true,

// test types
strict: true,
// test types
strict: true,

// Avoid writing to disk
noEmit: true,
// Avoid writing to disk
noEmit: true,

// Loads external files
isolatedModules: true,
skipDefaultLibCheck: false,
skipLibCheck: false,
},
});
// Loads external files
isolatedModules: true,
skipDefaultLibCheck: false,
skipLibCheck: false,
},
});

program.getSemanticDiagnostics(program.getSourceFile(filePath));
},
},
],
benchmarker: "tinybench",
program.getSemanticDiagnostics(program.getSourceFile(filePath));
},
},
],
benchmarker: 'tinybench',
};
11 changes: 6 additions & 5 deletions src/underscore-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const underscore = require('underscore');
const assert = require('node:assert');

module.exports = {
name: 'underscore',
Expand All @@ -7,19 +8,19 @@ module.exports = {
{
name: '.chunk',
fn: () => {
underscore.chunk(['a', 'b', 'c', 'd'], 2);
assert.ok(underscore.chunk(['a', 'b', 'c', 'd'], 2));
},
},
{
name: '.groupBy',
fn: () => {
underscore.groupBy([6.1, 4.2, 6.3], Math.floor);
assert.ok(underscore.groupBy([6.1, 4.2, 6.3], Math.floor));
},
},
{
name: '.includes',
fn: () => {
underscore.includes({ 'a': 1, 'b': 2 }, 1);
assert.ok(underscore.includes({ 'a': 1, 'b': 2 }, 1));
},
},
{
Expand All @@ -31,9 +32,9 @@ module.exports = {
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 36 }
];
underscore.sortBy(users, ['user', 'age'], ['asc', 'desc']);
assert.ok(underscore.sortBy(users, ['user', 'age'], ['asc', 'desc']));
}
}
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
2 changes: 1 addition & 1 deletion src/winston-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ module.exports = {
},
},
],
benchmarker: 'tinybench',
benchmarker: 'bench-node',
};
Loading