Skip to content

Commit 90bbab6

Browse files
BridgeARtargos
authored andcommitted
benchmark: refactor util benchmarks
This significantly reduces the benchmark runtime. It removes to many variations that do not provide any benefit and reduces the iterations. Backport-PR-URL: #23039 PR-URL: #22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 92e0f38 commit 90bbab6

8 files changed

+18
-28
lines changed

benchmark/util/format.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const inputs = {
1616
};
1717

1818
const bench = common.createBenchmark(main, {
19-
n: [4e6],
19+
n: [1e5],
2020
type: Object.keys(inputs)
2121
});
2222

benchmark/util/inspect-array.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const common = require('../common');
44
const util = require('util');
55

66
const bench = common.createBenchmark(main, {
7-
n: [1e3],
8-
len: [1e5],
7+
n: [5e2],
8+
len: [1e2, 1e5],
99
type: [
1010
'denseArray',
1111
'sparseArray',

benchmark/util/inspect-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const util = require('util');
44
const common = require('../common.js');
55

6-
const bench = common.createBenchmark(main, { n: [1e6] });
6+
const bench = common.createBenchmark(main, { n: [2e4] });
77

88
function main({ n }) {
99
const proxyA = new Proxy({}, { get: () => {} });

benchmark/util/inspect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const opts = {
99
none: undefined
1010
};
1111
const bench = common.createBenchmark(main, {
12-
n: [2e6],
12+
n: [2e4],
1313
method: [
1414
'Object',
1515
'Object_empty',
@@ -81,7 +81,7 @@ function main({ method, n, option }) {
8181
benchmark(n, new Error('error'), options);
8282
break;
8383
case 'Array':
84-
benchmark(n, Array(20).fill().map((_, i) => i), options);
84+
benchmark(n, Array(50).fill().map((_, i) => i), options);
8585
break;
8686
case 'TypedArray':
8787
obj = new Uint8Array(Array(50).fill().map((_, i) => i));

benchmark/util/normalize-encoding.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@ const assert = require('assert');
55

66
const groupedInputs = {
77
group_common: ['undefined', 'utf8', 'utf-8', 'base64',
8-
'binary', 'latin1', 'ucs-2'],
9-
group_upper: ['UTF-8', 'UTF8', 'UCS2', 'UTF-16LE',
10-
'UTF16LE', 'BASE64', 'UCS-2'],
11-
group_uncommon: ['foo', '1', 'false', 'undefined', '[]', '{}'],
8+
'binary', 'latin1', 'ucs2'],
9+
group_upper: ['UTF-8', 'UTF8', 'UCS2',
10+
'UTF16LE', 'BASE64', 'UCS2'],
11+
group_uncommon: ['foo'],
1212
group_misc: ['', 'utf16le', 'hex', 'HEX', 'BINARY']
1313
};
1414

1515
const inputs = [
16-
'',
17-
'utf8', 'utf-8', 'UTF-8',
18-
'UTF8', 'Utf8', 'uTf-8', 'utF-8',
19-
'ucs2', 'UCS2', 'UcS2',
20-
'ucs-2', 'UCS-2', 'UcS-2',
21-
'utf16le', 'utf-16le', 'UTF-16LE', 'UTF16LE',
16+
'', 'utf8', 'utf-8', 'UTF-8', 'UTF8', 'Utf8',
17+
'ucs2', 'UCS2', 'utf16le', 'UTF16LE',
2218
'binary', 'BINARY', 'latin1', 'base64', 'BASE64',
23-
'hex', 'HEX', 'foo', '1', 'false', 'undefined', '[]', '{}'];
19+
'hex', 'HEX', 'foo', 'undefined'
20+
];
2421

2522
const bench = common.createBenchmark(main, {
2623
input: inputs.concat(Object.keys(groupedInputs)),
27-
n: [1e7]
24+
n: [1e5]
2825
}, {
2926
flags: '--expose-internals'
3027
});
@@ -39,16 +36,8 @@ function getInput(input) {
3936
return groupedInputs.group_uncommon;
4037
case 'group_misc':
4138
return groupedInputs.group_misc;
42-
case '1':
43-
return [1];
44-
case 'false':
45-
return [false];
4639
case 'undefined':
4740
return [undefined];
48-
case '[]':
49-
return [[]];
50-
case '{}':
51-
return [{}];
5241
default:
5342
return [input];
5443
}

benchmark/util/splice-one.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../common');
44

55
const bench = common.createBenchmark(main, {
6-
n: [1e7],
6+
n: [1e5],
77
pos: ['start', 'middle', 'end'],
88
size: [10, 100, 500],
99
}, { flags: ['--expose-internals'] });

benchmark/util/type-check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const bench = common.createBenchmark(main, {
2929
type: Object.keys(args),
3030
version: ['native', 'js'],
3131
argument: ['true', 'false-primitive', 'false-object'],
32-
n: [5e6]
32+
n: [1e5]
3333
}, {
3434
flags: ['--expose-internals']
3535
});

test/parallel/test-benchmark-util.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ runBenchmark('util',
1313
'pos=start',
1414
'size=1',
1515
'type=',
16+
'len=1',
1617
'version=native'],
1718
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

Comments
 (0)