Skip to content

Commit c25d4d6

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

9 files changed

+30
-36
lines changed

benchmark/es/defaultparams-bench.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ function runDefaultParams(n) {
3838
bench.end(n / 1e6);
3939
}
4040

41-
function main(conf) {
42-
const n = +conf.millions * 1e6;
41+
function main({ millions, method }) {
42+
const n = millions * 1e6;
4343

44-
switch (conf.method) {
44+
switch (method) {
4545
case '':
4646
// Empty string falls through to next line as default, mostly for tests.
4747
case 'withoutdefaults':

benchmark/es/destructuring-bench.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ function runSwapDestructured(n) {
3434
bench.end(n / 1e6);
3535
}
3636

37-
function main(conf) {
38-
const n = +conf.millions * 1e6;
37+
function main({ millions, method }) {
38+
const n = millions * 1e6;
3939

40-
switch (conf.method) {
40+
switch (method) {
4141
case '':
4242
// Empty string falls through to next line as default, mostly for tests.
4343
case 'swap':

benchmark/es/destructuring-object-bench.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ function runDestructured(n) {
3333
bench.end(n / 1e6);
3434
}
3535

36-
function main(conf) {
37-
const n = +conf.millions * 1e6;
36+
function main({ millions, method }) {
37+
const n = millions * 1e6;
3838

39-
switch (conf.method) {
39+
switch (method) {
4040
case '':
4141
// Empty string falls through to next line as default, mostly for tests.
4242
case 'normal':

benchmark/es/foreach-bench.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ function useForEach(n, items) {
5252
bench.end(n / 1e6);
5353
}
5454

55-
function main(conf) {
56-
const n = +conf.millions * 1e6;
57-
const count = +conf.count;
58-
55+
function main({ millions, count, method }) {
56+
const n = millions * 1e6;
5957
const items = new Array(count);
6058
var i;
6159
var fn;
6260
for (i = 0; i < count; i++)
6361
items[i] = i;
6462

65-
switch (conf.method) {
63+
switch (method) {
6664
case '':
6765
// Empty string falls through to next line as default, mostly for tests.
6866
case 'for':

benchmark/es/map-bench.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ function runMap(n) {
108108
bench.end(n / 1e6);
109109
}
110110

111-
function main(conf) {
112-
const n = +conf.millions * 1e6;
111+
function main({ millions, method }) {
112+
const n = millions * 1e6;
113113

114-
switch (conf.method) {
114+
switch (method) {
115115
case '':
116116
// Empty string falls through to next line as default, mostly for tests.
117117
case 'object':

benchmark/es/restparams-bench.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function runUseArguments(n) {
6060
bench.end(n / 1e6);
6161
}
6262

63-
function main(conf) {
64-
const n = +conf.millions * 1e6;
63+
function main({ millions, method }) {
64+
const n = millions * 1e6;
6565

66-
switch (conf.method) {
66+
switch (method) {
6767
case '':
6868
// Empty string falls through to next line as default, mostly for tests.
6969
case 'copy':

benchmark/es/spread-bench.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ function makeTest(count, rest) {
2323
}
2424
}
2525

26-
function main(conf) {
27-
const n = +conf.millions * 1e6;
28-
const ctx = conf.context === 'context' ? {} : null;
29-
var fn = makeTest(conf.count, conf.rest);
30-
const args = new Array(conf.count);
26+
function main({ millions, context, count, rest, method }) {
27+
const n = millions * 1e6;
28+
const ctx = context === 'context' ? {} : null;
29+
var fn = makeTest(count, rest);
30+
const args = new Array(count);
3131
var i;
32-
for (i = 0; i < conf.count; i++)
32+
for (i = 0; i < count; i++)
3333
args[i] = i;
3434

35-
switch (conf.method) {
35+
switch (method) {
3636
case '':
3737
// Empty string falls through to next line as default, mostly for tests.
3838
case 'apply':

benchmark/es/string-concatenations.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ const configs = {
1717
const bench = common.createBenchmark(main, configs);
1818

1919

20-
function main(conf) {
21-
const n = +conf.n;
22-
20+
function main({ n, mode }) {
2321
const str = 'abc';
2422
const num = 123;
2523

2624
let string;
2725

28-
switch (conf.mode) {
26+
switch (mode) {
2927
case '':
3028
// Empty string falls through to next line as default, mostly for tests.
3129
case 'multi-concat':

benchmark/es/string-repeat.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ const configs = {
1212

1313
const bench = common.createBenchmark(main, configs);
1414

15-
function main(conf) {
16-
const n = +conf.n;
17-
const size = +conf.size;
18-
const character = conf.encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '🐎'
15+
function main({ n, size, encoding, mode }) {
16+
const character = encoding === 'ascii' ? 'a' : '\ud83d\udc0e'; // '🐎'
1917

2018
let str;
2119

22-
switch (conf.mode) {
20+
switch (mode) {
2321
case '':
2422
// Empty string falls through to next line as default, mostly for tests.
2523
case 'Array':

0 commit comments

Comments
 (0)