Skip to content

Commit ea19f7d

Browse files
BridgeARevanlucas
authored andcommitted
benchmark: use destructuring
This applies to all `async_hooks`, `dns`, `cluster`, `domain` and `module` benchmarks. PR-URL: #18250 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent cd9bc8b commit ea19f7d

File tree

5 files changed

+20
-30
lines changed

5 files changed

+20
-30
lines changed

benchmark/async_hooks/gc-tracking.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ function endAfterGC(n) {
2121
});
2222
}
2323

24-
function main(conf) {
25-
const n = +conf.n;
26-
27-
switch (conf.method) {
24+
function main({ n, method }) {
25+
switch (method) {
2826
case 'trackingEnabled':
2927
bench.start();
3028
for (let i = 0; i < n; i++) {

benchmark/cluster/echo.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@ if (cluster.isMaster) {
1010
n: [1e5]
1111
});
1212

13-
function main(conf) {
14-
const n = +conf.n;
15-
const workers = +conf.workers;
16-
const sends = +conf.sendsPerBroadcast;
17-
const expectedPerBroadcast = sends * workers;
18-
var payload;
13+
function main({ n, workers, sendsPerBroadcast, payload }) {
14+
const expectedPerBroadcast = sendsPerBroadcast * workers;
1915
var readies = 0;
2016
var broadcasts = 0;
2117
var msgCount = 0;
18+
var data;
2219

23-
switch (conf.payload) {
20+
switch (payload) {
2421
case 'string':
25-
payload = 'hello world!';
22+
data = 'hello world!';
2623
break;
2724
case 'object':
28-
payload = { action: 'pewpewpew', powerLevel: 9001 };
25+
data = { action: 'pewpewpew', powerLevel: 9001 };
2926
break;
3027
default:
3128
throw new Error('Unsupported payload type');
@@ -51,8 +48,8 @@ if (cluster.isMaster) {
5148
}
5249
for (id in cluster.workers) {
5350
const worker = cluster.workers[id];
54-
for (var i = 0; i < sends; ++i)
55-
worker.send(payload);
51+
for (var i = 0; i < sendsPerBroadcast; ++i)
52+
worker.send(data);
5653
}
5754
}
5855

benchmark/dns/lookup.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ const bench = common.createBenchmark(main, {
99
n: [5e6]
1010
});
1111

12-
function main(conf) {
13-
const name = conf.name;
14-
const n = +conf.n;
15-
const all = conf.all === 'true' ? true : false;
12+
function main({ name, n, all }) {
1613
var i = 0;
1714

18-
if (all) {
15+
if (all === 'true') {
1916
const opts = { all: true };
2017
bench.start();
2118
(function cb() {

benchmark/domain/domain-fn-args.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ const common = require('../common.js');
33
const domain = require('domain');
44

55
const bench = common.createBenchmark(main, {
6-
arguments: [0, 1, 2, 3],
6+
args: [0, 1, 2, 3],
77
n: [10]
88
});
99

1010
const bdomain = domain.create();
1111
const gargs = [1, 2, 3];
1212

13-
function main(conf) {
14-
15-
const n = +conf.n;
16-
const myArguments = gargs.slice(0, conf.arguments);
13+
function main({ n, args }) {
14+
const myArguments = gargs.slice(0, args);
1715
bench.start();
1816

1917
bdomain.enter();

benchmark/module/module-loader.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const bench = common.createBenchmark(main, {
1212
useCache: ['true', 'false']
1313
});
1414

15-
function main(conf) {
16-
const n = +conf.thousands * 1e3;
15+
function main({ thousands, fullPath, useCache }) {
16+
const n = thousands * 1e3;
1717

1818
refreshTmpDir();
1919
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
@@ -30,10 +30,10 @@ function main(conf) {
3030
);
3131
}
3232

33-
if (conf.fullPath === 'true')
34-
measureFull(n, conf.useCache === 'true');
33+
if (fullPath === 'true')
34+
measureFull(n, useCache === 'true');
3535
else
36-
measureDir(n, conf.useCache === 'true');
36+
measureDir(n, useCache === 'true');
3737

3838
refreshTmpDir();
3939
}

0 commit comments

Comments
 (0)