Skip to content
26 changes: 18 additions & 8 deletions benchmark/util/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
const common = require('../common');
const assert = require('assert');

const bench = common.createBenchmark(main, {
n: [1e5],
modifyPrototype: [1, 0],
emitWarningSync: [1, 0],
}, {
flags: ['--expose-internals'],
});
const bench = common.createBenchmark(
main,
{
n: [1000],
modifyPrototype: [1, 0],
emitWarningSync: [1, 0],
},
{
flags: ['--expose-internals'],
},
);

function simpleFunction(x) {
return x * 2 + (new Array(1000)).fill(0).map((_, i) => i).reduce((a, b) => a + b, 0);
return (
x * 2 +
new Array(1000)
.fill(0)
.map((_, i) => i)
.reduce((a, b) => a + b, 0)
);
}

function main({ n, modifyPrototype, emitWarningSync }) {
Expand Down
11 changes: 9 additions & 2 deletions benchmark/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ const inputs = {
'no-replace-2': ['foobar', 'yeah', 'mensch', 5],
'only-objects': [{ msg: 'This is an error' }, { msg: 'This is an error' }],
'many-%': ['replace%%%%s%%%%many%s%s%s', 'percent'],
'object-to-string': ['foo %s bar', { toString() { return 'bla'; } }],
'object-to-string': [
'foo %s bar',
{
toString() {
return 'bla';
},
},
],
'object-%s': ['foo %s bar', { a: true, b: false }],
};

const bench = common.createBenchmark(main, {
n: [1e6],
n: [100],
type: Object.keys(inputs),
});

Expand Down
2 changes: 1 addition & 1 deletion benchmark/util/get-callsite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { getCallSites } = require('node:util');
const assert = require('node:assert');

const bench = common.createBenchmark(main, {
n: [1e6],
n: [100],
method: ['ErrorCallSites', 'ErrorCallSitesSerialized', 'CPP'],
});

Expand Down
12 changes: 3 additions & 9 deletions benchmark/util/inspect-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ const common = require('../common');
const util = require('util');

const bench = common.createBenchmark(main, {
n: [5e3],
n: [10],
len: [1e2, 1e5],
type: [
'denseArray',
'sparseArray',
'mixedArray',
'denseArray_showHidden',
],
type: ['denseArray', 'sparseArray', 'mixedArray', 'denseArray_showHidden'],
});

function main({ n, len, type }) {
Expand All @@ -29,8 +24,7 @@ function main({ n, len, type }) {
case 'sparseArray':
break;
case 'mixedArray':
for (let i = 0; i < n; i += 2)
arr[i] = i;
for (let i = 0; i < n; i += 2) arr[i] = i;
break;
default:
throw new Error(`Unsupported type ${type}`);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/util/inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const util = require('util');
const common = require('../common.js');

const bench = common.createBenchmark(main, {
n: [1e5],
n: [100],
showProxy: [0, 1],
isProxy: [0, 1],
});
Expand Down
50 changes: 34 additions & 16 deletions benchmark/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const opts = {
none: undefined,
};
const bench = common.createBenchmark(main, {
n: [8e4],
n: [1000],
method: [
'Object',
'Object_empty',
Expand Down Expand Up @@ -47,18 +47,22 @@ function main({ method, n, option }) {
benchmark(n, {}, options);
break;
case 'Object_deep_ln':
if (options)
options.depth = Infinity;
obj = { first:
{ second:
{ third:
{ a: 'first',
b: 'second',
c: 'third',
d: 'fourth',
e: 'fifth',
f: 'sixth',
g: 'seventh' } } } };
if (options) options.depth = Infinity;
obj = {
first: {
second: {
third: {
a: 'first',
b: 'second',
c: 'third',
d: 'fourth',
e: 'fifth',
f: 'sixth',
g: 'seventh',
},
},
},
};
benchmark(n, obj, options || { depth: Infinity });
break;
case 'String':
Expand All @@ -81,14 +85,28 @@ function main({ method, n, option }) {
benchmark(n, new Error('error'), options);
break;
case 'Array':
benchmark(n, Array(50).fill().map((_, i) => i), options);
benchmark(
n,
Array(50)
.fill()
.map((_, i) => i),
options,
);
break;
case 'TypedArray':
obj = new Uint8Array(Array(50).fill().map((_, i) => i));
obj = new Uint8Array(
Array(50)
.fill()
.map((_, i) => i),
);
benchmark(n, obj, options);
break;
case 'TypedArray_extra':
obj = new Uint8Array(Array(50).fill().map((_, i) => i));
obj = new Uint8Array(
Array(50)
.fill()
.map((_, i) => i),
);
obj.foo = 'bar';
obj[Symbol('baz')] = 5;
benchmark(n, obj, options);
Expand Down
7 changes: 5 additions & 2 deletions benchmark/util/parse-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ const util = require('node:util');
const assert = require('node:assert');

const bench = createBenchmark(main, {
n: 3e4,
n: 10,
});

const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env'), 'utf-8');
const env = fs.readFileSync(
path.resolve(__dirname, '../fixtures/valid.env'),
'utf-8',
);

function main({ n }) {
let noDead;
Expand Down
18 changes: 10 additions & 8 deletions benchmark/util/priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

const common = require('../common');

const bench = common.createBenchmark(main, {
n: [1e5],
}, { flags: ['--expose-internals'] });
const bench = common.createBenchmark(
main,
{
n: [100],
},
{ flags: ['--expose-internals'] },
);

function main({ n, type }) {
function main({ n }) {
const PriorityQueue = require('internal/priority_queue');
const queue = new PriorityQueue();
bench.start();
for (let i = 0; i < n; i++)
queue.insert(Math.random() * 1e7 | 0);
for (let i = 0; i < n; i++)
queue.shift();
for (let i = 0; i < n; i++) queue.insert((Math.random() * 1e7) | 0);
for (let i = 0; i < n; i++) queue.shift();
bench.end(n);
}
14 changes: 9 additions & 5 deletions benchmark/util/splice-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

const common = require('../common');

const bench = common.createBenchmark(main, {
n: [5e6],
pos: ['start', 'middle', 'end'],
size: [10, 100, 500],
}, { flags: ['--expose-internals'] });
const bench = common.createBenchmark(
main,
{
n: [1000],
pos: ['start', 'middle', 'end'],
size: [10, 100, 500],
},
{ flags: ['--expose-internals'] },
);

function main({ n, pos, size }) {
const { spliceOne } = require('internal/util');
Expand Down
2 changes: 1 addition & 1 deletion benchmark/util/style-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, {
messageType: ['string', 'number', 'boolean', 'invalid'],
format: ['red', 'italic', 'invalid'],
validateStream: [1, 0],
n: [1e3],
n: [100],
});

function main({ messageType, format, validateStream, n }) {
Expand Down
10 changes: 4 additions & 6 deletions benchmark/util/text-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
len: [32, 256, 1024, 1024 * 8],
n: [1e6],
len: [32, 1024, 1024 * 8],
n: [1000],
type: ['one-byte-string', 'two-byte-string', 'ascii'],
op: ['encode', 'encodeInto'],
});
Expand All @@ -31,8 +31,7 @@ function main({ n, op, len, type }) {
const expected = encoder.encode(input);
let result;
bench.start();
for (let i = 0; i < n; i++)
result = encoder.encode(input);
for (let i = 0; i < n; i++) result = encoder.encode(input);
bench.end(n);
assert.deepStrictEqual(result, expected);
} else {
Expand All @@ -41,8 +40,7 @@ function main({ n, op, len, type }) {
const expectedStats = encoder.encodeInto(input, expected);
let result;
bench.start();
for (let i = 0; i < n; i++)
result = encoder.encodeInto(input, subarray);
for (let i = 0; i < n; i++) result = encoder.encodeInto(input, subarray);
bench.end(n);
assert.deepStrictEqual(subarray, expected);
assert.deepStrictEqual(result, expectedStats);
Expand Down
20 changes: 12 additions & 8 deletions benchmark/util/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ const args = {
},
};

const bench = common.createBenchmark(main, {
type: Object.keys(args),
version: ['native', 'js'],
argument: ['true', 'false-primitive', 'false-object'],
n: [1e6],
}, {
flags: ['--expose-internals', '--no-warnings'],
});
const bench = common.createBenchmark(
main,
{
type: Object.keys(args),
version: ['native', 'js'],
argument: ['true', 'false-primitive', 'false-object'],
n: [1000],
},
{
flags: ['--expose-internals', '--no-warnings'],
},
);

function main({ type, argument, version, n }) {
const util = common.binding('util');
Expand Down
Loading