Skip to content

Commit

Permalink
benchmark: refactor for consistent style
Browse files Browse the repository at this point in the history
Code in benchmark directory sometimes uses `function () {}` for
anonymous callbacks and sometimes uses `() => {}`. Multi-line arrays
sometimes have a trailing comma and sometimes do not. Update to always
use arrow functions for anonymous callbacks and trailing commas for
multiline arrays.

PR-URL: nodejs#25944
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott committed Feb 7, 2019
1 parent d310d8d commit 29e74d4
Show file tree
Hide file tree
Showing 96 changed files with 158 additions and 164 deletions.
6 changes: 2 additions & 4 deletions benchmark/_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const path = require('path');
// Create an object of all benchmark scripts
const benchmarks = {};
fs.readdirSync(__dirname)
.filter(function(name) {
return fs.statSync(path.resolve(__dirname, name)).isDirectory();
})
.forEach(function(category) {
.filter((name) => fs.statSync(path.resolve(__dirname, name)).isDirectory())
.forEach((category) => {
benchmarks[category] = fs.readdirSync(path.resolve(__dirname, category))
.filter((filename) => filename[0] !== '.' && filename[0] !== '_');
});
Expand Down
6 changes: 2 additions & 4 deletions benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const chars = [
'hello brendan!!!', // 1 byte
'ΰαβγδεζηθικλμνξο', // 2 bytes
'挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿', // 3 bytes
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢' // 4 bytes
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢', // 4 bytes
];

function main({ n, len, encoding }) {
Expand All @@ -33,9 +33,7 @@ function main({ n, len, encoding }) {
}

// Check the result to ensure it is *properly* optimized
results = strings.map(function(val) {
return Buffer.byteLength(val, encoding);
});
results = strings.map((val) => Buffer.byteLength(val, encoding));
}

bench.start();
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
'fill("t", "utf8")',
'fill("t", 0, "utf8")',
'fill("t", 0)',
'fill(Buffer.alloc(1), 0)'
'fill(Buffer.alloc(1), 0)',
],
size: [2 ** 8, 2 ** 13, 2 ** 16],
n: [2e4]
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
'string',
'string-utf8',
'string-base64',
'object'
'object',
],
len: [10, 2048],
n: [2048]
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const searchStrings = [
'Soo--oop',
'aaaaaaaaaaaaaaaaa',
'venture to go near the house till she had brought herself down to',
'</i> to the Caterpillar'
'</i> to the Caterpillar',
];

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-normalize-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const bench = common.createBenchmark(main, {
'utf16le',
'UTF16LE',
'utf8',
'UTF8'
'UTF8',
],
n: [1e6]
}, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const types = [
'IntBE',
'IntLE',
'UIntBE',
'UIntLE'
'UIntLE',
];

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const types = [
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE'
'DoubleBE',
];

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-write-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const common = require('../common.js');
const bench = common.createBenchmark(main, {
encoding: [
'', 'utf8', 'ascii', 'hex', 'UCS-2', 'utf16le', 'latin1', 'binary'
'', 'utf8', 'ascii', 'hex', 'UCS-2', 'utf16le', 'latin1', 'binary',
],
args: [ '', 'offset', 'offset+length' ],
len: [10, 2048],
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const types = [
'FloatLE',
'FloatBE',
'DoubleLE',
'DoubleBE'
'DoubleBE',
];

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const types = [
'Float32LE',
'Float32BE',
'Float64LE',
'Float64BE'
'Float64BE',
];

const bench = common.createBenchmark(main, {
Expand Down
8 changes: 3 additions & 5 deletions benchmark/child_process/child-process-read-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
const bench = common.createBenchmark(main, {
len: [
64, 256, 1024, 4096, 16384, 65536,
65536 << 4, 65536 << 8
65536 << 4, 65536 << 8,
],
dur: [5]
});
Expand All @@ -27,11 +27,9 @@ if (process.argv[2] === 'child') {
[process.argv[1], 'child', len], options);

var bytes = 0;
child.on('message', function(msg) {
bytes += msg.length;
});
child.on('message', (msg) => { bytes += msg.length; });

setTimeout(function() {
setTimeout(() => {
child.kill();
bench.end(bytes);
}, dur * 1000);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/child_process/child-process-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ function main({ dur, len }) {
const child = child_process.spawn('yes', [msg], options);

var bytes = 0;
child.stdout.on('data', function(msg) {
child.stdout.on('data', (msg) => {
bytes += msg.length;
});

setTimeout(function() {
setTimeout(() => {
if (process.platform === 'win32') {
// Sometimes there's a yes.exe process left hanging around on Windows...
child_process.execSync(`taskkill /f /t /pid ${child.pid}`);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/child_process/spawn-echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function go(n, left) {
return bench.end(n);

const child = spawn('echo', ['hello']);
child.on('exit', function(code) {
child.on('exit', (code) => {
if (code)
process.exit(code);
else
Expand Down
2 changes: 1 addition & 1 deletion benchmark/cluster/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (cluster.isMaster) {
}
}
} else {
process.on('message', function(msg) {
process.on('message', (msg) => {
process.send(msg);
});
}
4 changes: 2 additions & 2 deletions benchmark/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (showProgress) {
execPath: cli.optional[job.binary]
});

child.on('message', function(data) {
child.on('message', (data) => {
if (data.type === 'report') {
// Construct configuration string, " A=a, B=b, ..."
let conf = '';
Expand All @@ -95,7 +95,7 @@ if (showProgress) {
}
});

child.once('close', function(code) {
child.once('close', (code) => {
if (code) {
process.exit(code);
return;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/crypto/cipher-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ function main({ api, cipher, type, len, writes }) {

function streamWrite(alice, bob, message, encoding, writes) {
var written = 0;
bob.on('data', function(c) {
bob.on('data', (c) => {
written += c.length;
});

bob.on('end', function() {
bob.on('end', () => {
// Gbits
const bits = written * 8;
const gbits = bits / (1024 * 1024 * 1024);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/crypto/rsa-encrypt-decrypt-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const keylen_list = ['1024', '2048', '4096'];
const RSA_PublicPem = {};
const RSA_PrivatePem = {};

keylen_list.forEach(function(key) {
keylen_list.forEach((key) => {
RSA_PublicPem[key] =
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
RSA_PrivatePem[key] =
Expand Down
2 changes: 1 addition & 1 deletion benchmark/crypto/rsa-sign-verify-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const keylen_list = ['1024', '2048'];
const RSA_PublicPem = {};
const RSA_PrivatePem = {};

keylen_list.forEach(function(key) {
keylen_list.forEach((key) => {
RSA_PublicPem[key] =
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
RSA_PrivatePem[key] =
Expand Down
4 changes: 2 additions & 2 deletions benchmark/dgram/array-vs-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ function main({ dur, len, num, type, chunks }) {
}
}

socket.on('listening', function() {
socket.on('listening', () => {
bench.start();
onsend();

setTimeout(function() {
setTimeout(() => {
const bytes = sent * len;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/dgram/multi-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ function main({ dur, len, num, type, chunks }) {
}
}

socket.on('listening', function() {
socket.on('listening', () => {
bench.start();
onsend();

setTimeout(function() {
setTimeout(() => {
const bytes = (type === 'send' ? sent : received) * len;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
});

socket.on('message', function() {
socket.on('message', () => {
received++;
});

Expand Down
6 changes: 3 additions & 3 deletions benchmark/dgram/offset-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ function main({ dur, len, num, type }) {
}
}

socket.on('listening', function() {
socket.on('listening', () => {
bench.start();
onsend();

setTimeout(function() {
setTimeout(() => {
const bytes = (type === 'send' ? sent : received) * chunk.length;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
});

socket.on('message', function() {
socket.on('message', () => {
received++;
});

Expand Down
6 changes: 3 additions & 3 deletions benchmark/dgram/single-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ function main({ dur, len, num, type }) {
}
}

socket.on('listening', function() {
socket.on('listening', () => {
bench.start();
onsend();

setTimeout(function() {
setTimeout(() => {
const bytes = (type === 'send' ? sent : received) * chunk.length;
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
bench.end(gbits);
process.exit(0);
}, dur * 1000);
});

socket.on('message', function() {
socket.on('message', () => {
received++;
});

Expand Down
2 changes: 1 addition & 1 deletion benchmark/es/map-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const assert = require('assert');
const bench = common.createBenchmark(main, {
method: [
'object', 'nullProtoObject', 'nullProtoLiteralObject', 'storageObject',
'fakeMap', 'map'
'fakeMap', 'map',
],
n: [1e6]
});
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-add-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function main({ n }) {

var k;
for (k = 0; k < 10; k += 1)
listeners.push(function() {});
listeners.push(() => {});

bench.start();
for (var i = 0; i < n; i += 1) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-emit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function main({ n, argc, listeners }) {
const ee = new EventEmitter();

for (var k = 0; k < listeners; k += 1)
ee.on('dummy', function() {});
ee.on('dummy', () => {});

var i;
switch (argc) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/events/ee-listener-count-on-prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function main({ n }) {
const ee = new EventEmitter();

for (var k = 0; k < 5; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
ee.on('dummy0', () => {});
ee.on('dummy1', () => {});
}

bench.start();
Expand Down
4 changes: 2 additions & 2 deletions benchmark/events/ee-listeners-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function main({ n }) {
ee.setMaxListeners(101);

for (var k = 0; k < 50; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
ee.on('dummy0', () => {});
ee.on('dummy1', () => {});
}

bench.start();
Expand Down
4 changes: 2 additions & 2 deletions benchmark/events/ee-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function main({ n }) {
const ee = new EventEmitter();

for (var k = 0; k < 5; k += 1) {
ee.on('dummy0', function() {});
ee.on('dummy1', function() {});
ee.on('dummy0', () => {});
ee.on('dummy1', () => {});
}

bench.start();
Expand Down
4 changes: 2 additions & 2 deletions benchmark/fixtures/simple-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const useDomains = process.env.NODE_USE_DOMAINS;
if (useDomains) {
var domain = require('domain');
const gdom = domain.create();
gdom.on('error', function(er) {
gdom.on('error', (er) => {
console.error('Error on global domain', er);
throw er;
});
gdom.enter();
}

module.exports = http.createServer(function(req, res) {
module.exports = http.createServer((req, res) => {
if (useDomains) {
const dom = domain.create();
dom.add(req);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/bench-readdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function main({ n, dir, withFileTypes }) {
(function r(cntr) {
if (cntr-- <= 0)
return bench.end(n);
fs.readdir(fullPath, { withFileTypes }, function() {
fs.readdir(fullPath, { withFileTypes }, () => {
r(cntr);
});
}(n));
Expand Down
Loading

0 comments on commit 29e74d4

Please sign in to comment.