Skip to content

Commit

Permalink
benchmark: use destructuring
Browse files Browse the repository at this point in the history
This applies to all `async_hooks`, `dns`, `cluster`, `domain` and
`module` benchmarks.

PR-URL: nodejs#18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MayaLekova committed May 8, 2018
1 parent 572e5f7 commit c1b7471
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
6 changes: 2 additions & 4 deletions benchmark/async_hooks/gc-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ function endAfterGC(n) {
});
}

function main(conf) {
const n = +conf.n;

switch (conf.method) {
function main({ n, method }) {
switch (method) {
case 'trackingEnabled':
bench.start();
for (let i = 0; i < n; i++) {
Expand Down
19 changes: 8 additions & 11 deletions benchmark/cluster/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@ if (cluster.isMaster) {
n: [1e5]
});

function main(conf) {
const n = +conf.n;
const workers = +conf.workers;
const sends = +conf.sendsPerBroadcast;
const expectedPerBroadcast = sends * workers;
var payload;
function main({ n, workers, sendsPerBroadcast, payload }) {
const expectedPerBroadcast = sendsPerBroadcast * workers;
var readies = 0;
var broadcasts = 0;
var msgCount = 0;
var data;

switch (conf.payload) {
switch (payload) {
case 'string':
payload = 'hello world!';
data = 'hello world!';
break;
case 'object':
payload = { action: 'pewpewpew', powerLevel: 9001 };
data = { action: 'pewpewpew', powerLevel: 9001 };
break;
default:
throw new Error('Unsupported payload type');
Expand All @@ -51,8 +48,8 @@ if (cluster.isMaster) {
}
for (id in cluster.workers) {
const worker = cluster.workers[id];
for (var i = 0; i < sends; ++i)
worker.send(payload);
for (var i = 0; i < sendsPerBroadcast; ++i)
worker.send(data);
}
}

Expand Down
7 changes: 2 additions & 5 deletions benchmark/dns/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ const bench = common.createBenchmark(main, {
n: [5e6]
});

function main(conf) {
const name = conf.name;
const n = +conf.n;
const all = conf.all === 'true' ? true : false;
function main({ name, n, all }) {
var i = 0;

if (all) {
if (all === 'true') {
const opts = { all: true };
bench.start();
(function cb() {
Expand Down
8 changes: 3 additions & 5 deletions benchmark/domain/domain-fn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ const common = require('../common.js');
const domain = require('domain');

const bench = common.createBenchmark(main, {
arguments: [0, 1, 2, 3],
args: [0, 1, 2, 3],
n: [10]
});

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

function main(conf) {

const n = +conf.n;
const myArguments = gargs.slice(0, conf.arguments);
function main({ n, args }) {
const myArguments = gargs.slice(0, args);
bench.start();

bdomain.enter();
Expand Down
10 changes: 5 additions & 5 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const bench = common.createBenchmark(main, {
useCache: ['true', 'false']
});

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

refreshTmpDir();
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
Expand All @@ -30,10 +30,10 @@ function main(conf) {
);
}

if (conf.fullPath === 'true')
measureFull(n, conf.useCache === 'true');
if (fullPath === 'true')
measureFull(n, useCache === 'true');
else
measureDir(n, conf.useCache === 'true');
measureDir(n, useCache === 'true');

refreshTmpDir();
}
Expand Down

0 comments on commit c1b7471

Please sign in to comment.