Skip to content

Commit c4d16e8

Browse files
Trottaddaleax
authored andcommitted
benchmark: refactor for consistent style
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: #25944 Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2d57504 commit c4d16e8

File tree

96 files changed

+158
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+158
-164
lines changed

benchmark/_cli.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ const path = require('path');
66
// Create an object of all benchmark scripts
77
const benchmarks = {};
88
fs.readdirSync(__dirname)
9-
.filter(function(name) {
10-
return fs.statSync(path.resolve(__dirname, name)).isDirectory();
11-
})
12-
.forEach(function(category) {
9+
.filter((name) => fs.statSync(path.resolve(__dirname, name)).isDirectory())
10+
.forEach((category) => {
1311
benchmarks[category] = fs.readdirSync(path.resolve(__dirname, category))
1412
.filter((filename) => filename[0] !== '.' && filename[0] !== '_');
1513
});

benchmark/buffers/buffer-bytelength.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const chars = [
1212
'hello brendan!!!', // 1 byte
1313
'ΰαβγδεζηθικλμνξο', // 2 bytes
1414
'挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿', // 3 bytes
15-
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢' // 4 bytes
15+
'𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢', // 4 bytes
1616
];
1717

1818
function main({ n, len, encoding }) {
@@ -33,9 +33,7 @@ function main({ n, len, encoding }) {
3333
}
3434

3535
// Check the result to ensure it is *properly* optimized
36-
results = strings.map(function(val) {
37-
return Buffer.byteLength(val, encoding);
38-
});
36+
results = strings.map((val) => Buffer.byteLength(val, encoding));
3937
}
4038

4139
bench.start();

benchmark/buffers/buffer-fill.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
1212
'fill("t", "utf8")',
1313
'fill("t", 0, "utf8")',
1414
'fill("t", 0)',
15-
'fill(Buffer.alloc(1), 0)'
15+
'fill(Buffer.alloc(1), 0)',
1616
],
1717
size: [2 ** 8, 2 ** 13, 2 ** 16],
1818
n: [2e4]

benchmark/buffers/buffer-from.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
1212
'string',
1313
'string-utf8',
1414
'string-base64',
15-
'object'
15+
'object',
1616
],
1717
len: [10, 2048],
1818
n: [2048]

benchmark/buffers/buffer-indexof.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const searchStrings = [
1818
'Soo--oop',
1919
'aaaaaaaaaaaaaaaaa',
2020
'venture to go near the house till she had brought herself down to',
21-
'</i> to the Caterpillar'
21+
'</i> to the Caterpillar',
2222
];
2323

2424
const bench = common.createBenchmark(main, {

benchmark/buffers/buffer-normalize-encoding.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const bench = common.createBenchmark(main, {
2525
'utf16le',
2626
'UTF16LE',
2727
'utf8',
28-
'UTF8'
28+
'UTF8',
2929
],
3030
n: [1e6]
3131
}, {

benchmark/buffers/buffer-read-with-byteLength.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const types = [
55
'IntBE',
66
'IntLE',
77
'UIntBE',
8-
'UIntLE'
8+
'UIntLE',
99
];
1010

1111
const bench = common.createBenchmark(main, {

benchmark/buffers/buffer-read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const types = [
1515
'FloatLE',
1616
'FloatBE',
1717
'DoubleLE',
18-
'DoubleBE'
18+
'DoubleBE',
1919
];
2020

2121
const bench = common.createBenchmark(main, {

benchmark/buffers/buffer-write-string.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../common.js');
44
const bench = common.createBenchmark(main, {
55
encoding: [
6-
'', 'utf8', 'ascii', 'hex', 'UCS-2', 'utf16le', 'latin1', 'binary'
6+
'', 'utf8', 'ascii', 'hex', 'UCS-2', 'utf16le', 'latin1', 'binary',
77
],
88
args: [ '', 'offset', 'offset+length' ],
99
len: [10, 2048],

benchmark/buffers/buffer-write.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const types = [
1919
'FloatLE',
2020
'FloatBE',
2121
'DoubleLE',
22-
'DoubleBE'
22+
'DoubleBE',
2323
];
2424

2525
const bench = common.createBenchmark(main, {

benchmark/buffers/dataview-set.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const types = [
1515
'Float32LE',
1616
'Float32BE',
1717
'Float64LE',
18-
'Float64BE'
18+
'Float64BE',
1919
];
2020

2121
const bench = common.createBenchmark(main, {

benchmark/child_process/child-process-read-ipc.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (process.argv[2] === 'child') {
1313
const bench = common.createBenchmark(main, {
1414
len: [
1515
64, 256, 1024, 4096, 16384, 65536,
16-
65536 << 4, 65536 << 8
16+
65536 << 4, 65536 << 8,
1717
],
1818
dur: [5]
1919
});
@@ -27,11 +27,9 @@ if (process.argv[2] === 'child') {
2727
[process.argv[1], 'child', len], options);
2828

2929
var bytes = 0;
30-
child.on('message', function(msg) {
31-
bytes += msg.length;
32-
});
30+
child.on('message', (msg) => { bytes += msg.length; });
3331

34-
setTimeout(function() {
32+
setTimeout(() => {
3533
child.kill();
3634
bench.end(bytes);
3735
}, dur * 1000);

benchmark/child_process/child-process-read.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function main({ dur, len }) {
2525
const child = child_process.spawn('yes', [msg], options);
2626

2727
var bytes = 0;
28-
child.stdout.on('data', function(msg) {
28+
child.stdout.on('data', (msg) => {
2929
bytes += msg.length;
3030
});
3131

32-
setTimeout(function() {
32+
setTimeout(() => {
3333
if (process.platform === 'win32') {
3434
// Sometimes there's a yes.exe process left hanging around on Windows...
3535
child_process.execSync(`taskkill /f /t /pid ${child.pid}`);

benchmark/child_process/spawn-echo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function go(n, left) {
1515
return bench.end(n);
1616

1717
const child = spawn('echo', ['hello']);
18-
child.on('exit', function(code) {
18+
child.on('exit', (code) => {
1919
if (code)
2020
process.exit(code);
2121
else

benchmark/cluster/echo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (cluster.isMaster) {
6161
}
6262
}
6363
} else {
64-
process.on('message', function(msg) {
64+
process.on('message', (msg) => {
6565
process.send(msg);
6666
});
6767
}

benchmark/compare.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if (showProgress) {
7272
execPath: cli.optional[job.binary]
7373
});
7474

75-
child.on('message', function(data) {
75+
child.on('message', (data) => {
7676
if (data.type === 'report') {
7777
// Construct configuration string, " A=a, B=b, ..."
7878
let conf = '';
@@ -95,7 +95,7 @@ if (showProgress) {
9595
}
9696
});
9797

98-
child.once('close', function(code) {
98+
child.once('close', (code) => {
9999
if (code) {
100100
process.exit(code);
101101
return;

benchmark/crypto/cipher-stream.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ function main({ api, cipher, type, len, writes }) {
6666

6767
function streamWrite(alice, bob, message, encoding, writes) {
6868
var written = 0;
69-
bob.on('data', function(c) {
69+
bob.on('data', (c) => {
7070
written += c.length;
7171
});
7272

73-
bob.on('end', function() {
73+
bob.on('end', () => {
7474
// Gbits
7575
const bits = written * 8;
7676
const gbits = bits / (1024 * 1024 * 1024);

benchmark/crypto/rsa-encrypt-decrypt-throughput.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const keylen_list = ['1024', '2048', '4096'];
99
const RSA_PublicPem = {};
1010
const RSA_PrivatePem = {};
1111

12-
keylen_list.forEach(function(key) {
12+
keylen_list.forEach((key) => {
1313
RSA_PublicPem[key] =
1414
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
1515
RSA_PrivatePem[key] =

benchmark/crypto/rsa-sign-verify-throughput.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const keylen_list = ['1024', '2048'];
99
const RSA_PublicPem = {};
1010
const RSA_PrivatePem = {};
1111

12-
keylen_list.forEach(function(key) {
12+
keylen_list.forEach((key) => {
1313
RSA_PublicPem[key] =
1414
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
1515
RSA_PrivatePem[key] =

benchmark/dgram/array-vs-concat.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function main({ dur, len, num, type, chunks }) {
4343
}
4444
}
4545

46-
socket.on('listening', function() {
46+
socket.on('listening', () => {
4747
bench.start();
4848
onsend();
4949

50-
setTimeout(function() {
50+
setTimeout(() => {
5151
const bytes = sent * len;
5252
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
5353
bench.end(gbits);

benchmark/dgram/multi-buffer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ function main({ dur, len, num, type, chunks }) {
3333
}
3434
}
3535

36-
socket.on('listening', function() {
36+
socket.on('listening', () => {
3737
bench.start();
3838
onsend();
3939

40-
setTimeout(function() {
40+
setTimeout(() => {
4141
const bytes = (type === 'send' ? sent : received) * len;
4242
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
4343
bench.end(gbits);
4444
process.exit(0);
4545
}, dur * 1000);
4646
});
4747

48-
socket.on('message', function() {
48+
socket.on('message', () => {
4949
received++;
5050
});
5151

benchmark/dgram/offset-length.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ function main({ dur, len, num, type }) {
2929
}
3030
}
3131

32-
socket.on('listening', function() {
32+
socket.on('listening', () => {
3333
bench.start();
3434
onsend();
3535

36-
setTimeout(function() {
36+
setTimeout(() => {
3737
const bytes = (type === 'send' ? sent : received) * chunk.length;
3838
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
3939
bench.end(gbits);
4040
process.exit(0);
4141
}, dur * 1000);
4242
});
4343

44-
socket.on('message', function() {
44+
socket.on('message', () => {
4545
received++;
4646
});
4747

benchmark/dgram/single-buffer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ function main({ dur, len, num, type }) {
2929
}
3030
}
3131

32-
socket.on('listening', function() {
32+
socket.on('listening', () => {
3333
bench.start();
3434
onsend();
3535

36-
setTimeout(function() {
36+
setTimeout(() => {
3737
const bytes = (type === 'send' ? sent : received) * chunk.length;
3838
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
3939
bench.end(gbits);
4040
process.exit(0);
4141
}, dur * 1000);
4242
});
4343

44-
socket.on('message', function() {
44+
socket.on('message', () => {
4545
received++;
4646
});
4747

benchmark/es/map-bench.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const assert = require('assert');
66
const bench = common.createBenchmark(main, {
77
method: [
88
'object', 'nullProtoObject', 'nullProtoLiteralObject', 'storageObject',
9-
'fakeMap', 'map'
9+
'fakeMap', 'map',
1010
],
1111
n: [1e6]
1212
});

benchmark/events/ee-add-remove.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function main({ n }) {
1010

1111
var k;
1212
for (k = 0; k < 10; k += 1)
13-
listeners.push(function() {});
13+
listeners.push(() => {});
1414

1515
bench.start();
1616
for (var i = 0; i < n; i += 1) {

benchmark/events/ee-emit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function main({ n, argc, listeners }) {
1212
const ee = new EventEmitter();
1313

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

1717
var i;
1818
switch (argc) {

benchmark/events/ee-listener-count-on-prototype.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function main({ n }) {
88
const ee = new EventEmitter();
99

1010
for (var k = 0; k < 5; k += 1) {
11-
ee.on('dummy0', function() {});
12-
ee.on('dummy1', function() {});
11+
ee.on('dummy0', () => {});
12+
ee.on('dummy1', () => {});
1313
}
1414

1515
bench.start();

benchmark/events/ee-listeners-many.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function main({ n }) {
99
ee.setMaxListeners(101);
1010

1111
for (var k = 0; k < 50; k += 1) {
12-
ee.on('dummy0', function() {});
13-
ee.on('dummy1', function() {});
12+
ee.on('dummy0', () => {});
13+
ee.on('dummy1', () => {});
1414
}
1515

1616
bench.start();

benchmark/events/ee-listeners.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function main({ n }) {
88
const ee = new EventEmitter();
99

1010
for (var k = 0; k < 5; k += 1) {
11-
ee.on('dummy0', function() {});
12-
ee.on('dummy1', function() {});
11+
ee.on('dummy0', () => {});
12+
ee.on('dummy1', () => {});
1313
}
1414

1515
bench.start();

benchmark/fixtures/simple-http-server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const useDomains = process.env.NODE_USE_DOMAINS;
1313
if (useDomains) {
1414
var domain = require('domain');
1515
const gdom = domain.create();
16-
gdom.on('error', function(er) {
16+
gdom.on('error', (er) => {
1717
console.error('Error on global domain', er);
1818
throw er;
1919
});
2020
gdom.enter();
2121
}
2222

23-
module.exports = http.createServer(function(req, res) {
23+
module.exports = http.createServer((req, res) => {
2424
if (useDomains) {
2525
const dom = domain.create();
2626
dom.add(req);

benchmark/fs/bench-readdir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function main({ n, dir, withFileTypes }) {
1717
(function r(cntr) {
1818
if (cntr-- <= 0)
1919
return bench.end(n);
20-
fs.readdir(fullPath, { withFileTypes }, function() {
20+
fs.readdir(fullPath, { withFileTypes }, () => {
2121
r(cntr);
2222
});
2323
}(n));

0 commit comments

Comments
 (0)