Skip to content

Commit e00dac7

Browse files
BridgeARevanlucas
authored andcommitted
benchmark: (assert) use destructuring
PR-URL: #18250 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3543458 commit e00dac7

8 files changed

+23
-40
lines changed

benchmark/assert/deepequal-buffer.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ const bench = common.createBenchmark(main, {
1313
]
1414
});
1515

16-
function main(conf) {
17-
const n = +conf.n;
18-
const len = +conf.len;
16+
function main({ len, n, method }) {
1917
var i;
2018

2119
const data = Buffer.allocUnsafe(len + 1);
@@ -26,7 +24,7 @@ function main(conf) {
2624
data.copy(expected);
2725
data.copy(expectedWrong);
2826

29-
switch (conf.method) {
27+
switch (method) {
3028
case '':
3129
// Empty string falls through to next line as default, mostly for tests.
3230
case 'deepEqual':

benchmark/assert/deepequal-map.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ function benchmark(method, n, values, values2) {
3838
bench.end(n);
3939
}
4040

41-
function main(conf) {
42-
const n = +conf.n;
43-
const len = +conf.len;
44-
41+
function main({ n, len, method }) {
4542
const array = Array(len).fill(1);
4643
var values, values2;
4744

48-
switch (conf.method) {
45+
switch (method) {
4946
case '':
5047
// Empty string falls through to next line as default, mostly for tests.
5148
case 'deepEqual_primitiveOnly':

benchmark/assert/deepequal-object.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ function createObj(source, add = '') {
2525
}));
2626
}
2727

28-
function main(conf) {
29-
const size = conf.size;
30-
// TODO: Fix this "hack"
31-
const n = conf.n / size;
28+
function main({ size, n, method }) {
29+
// TODO: Fix this "hack". `n` should not be manipulated.
30+
n = n / size;
3231
var i;
3332

3433
const source = Array.apply(null, Array(size));
3534
const actual = createObj(source);
3635
const expected = createObj(source);
3736
const expectedWrong = createObj(source, '4');
3837

39-
switch (conf.method) {
38+
switch (method) {
4039
case '':
4140
// Empty string falls through to next line as default, mostly for tests.
4241
case 'deepEqual':

benchmark/assert/deepequal-prims-and-objs-big-array-set.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const primValues = {
1515
};
1616

1717
const bench = common.createBenchmark(main, {
18-
prim: Object.keys(primValues),
18+
primitive: Object.keys(primValues),
1919
n: [25],
2020
len: [1e5],
2121
method: [
@@ -30,10 +30,8 @@ const bench = common.createBenchmark(main, {
3030
]
3131
});
3232

33-
function main(conf) {
34-
const prim = primValues[conf.prim];
35-
const n = +conf.n;
36-
const len = +conf.len;
33+
function main({ n, len, primitive, method }) {
34+
const prim = primValues[primitive];
3735
const actual = [];
3836
const expected = [];
3937
const expectedWrong = [];
@@ -52,7 +50,7 @@ function main(conf) {
5250
const expectedSet = new Set(expected);
5351
const expectedWrongSet = new Set(expectedWrong);
5452

55-
switch (conf.method) {
53+
switch (method) {
5654
case '':
5755
// Empty string falls through to next line as default, mostly for tests.
5856
case 'deepEqual_Array':

benchmark/assert/deepequal-prims-and-objs-big-loop.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const primValues = {
1414
};
1515

1616
const bench = common.createBenchmark(main, {
17-
prim: Object.keys(primValues),
17+
primitive: Object.keys(primValues),
1818
n: [1e6],
1919
method: [
2020
'deepEqual',
@@ -24,16 +24,15 @@ const bench = common.createBenchmark(main, {
2424
]
2525
});
2626

27-
function main(conf) {
28-
const prim = primValues[conf.prim];
29-
const n = +conf.n;
27+
function main({ n, primitive, method }) {
28+
const prim = primValues[primitive];
3029
const actual = prim;
3130
const expected = prim;
3231
const expectedWrong = 'b';
3332
var i;
3433

3534
// Creates new array to avoid loop invariant code motion
36-
switch (conf.method) {
35+
switch (method) {
3736
case '':
3837
// Empty string falls through to next line as default, mostly for tests.
3938
case 'deepEqual':

benchmark/assert/deepequal-set.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,12 @@ function benchmark(method, n, values, values2) {
3838
bench.end(n);
3939
}
4040

41-
function main(conf) {
42-
const n = +conf.n;
43-
const len = +conf.len;
44-
41+
function main({ n, len, method }) {
4542
const array = Array(len).fill(1);
4643

4744
var values, values2;
4845

49-
switch (conf.method) {
46+
switch (method) {
5047
case '':
5148
// Empty string falls through to next line as default, mostly for tests.
5249
case 'deepEqual_primitiveOnly':

benchmark/assert/deepequal-typedarrays.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@ const bench = common.createBenchmark(main, {
2424
len: [1e6]
2525
});
2626

27-
function main(conf) {
28-
const type = conf.type;
27+
function main({ type, n, len, method }) {
2928
const clazz = global[type];
30-
const n = +conf.n;
31-
const len = +conf.len;
32-
3329
const actual = new clazz(len);
3430
const expected = new clazz(len);
3531
const expectedWrong = Buffer.alloc(len);
3632
const wrongIndex = Math.floor(len / 2);
3733
expectedWrong[wrongIndex] = 123;
3834
var i;
3935

40-
switch (conf.method) {
36+
switch (method) {
4137
case '':
4238
// Empty string falls through to next line as default, mostly for tests.
4339
case 'deepEqual':

benchmark/assert/throws.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ const bench = common.createBenchmark(main, {
1313
]
1414
});
1515

16-
function main(conf) {
17-
const n = +conf.n;
16+
function main({ n, method }) {
1817
const throws = () => { throw new TypeError('foobar'); };
1918
const doesNotThrow = () => { return 'foobar'; };
2019
const regExp = /foobar/;
2120
const message = 'failure';
2221
var i;
2322

24-
switch (conf.method) {
23+
switch (method) {
2524
case '':
2625
// Empty string falls through to next line as default, mostly for tests.
2726
case 'doesNotThrow':
@@ -54,6 +53,6 @@ function main(conf) {
5453
bench.end(n);
5554
break;
5655
default:
57-
throw new Error(`Unsupported method ${conf.method}`);
56+
throw new Error(`Unsupported method ${method}`);
5857
}
5958
}

0 commit comments

Comments
 (0)