diff options
author | Rich Trott <rtrott@gmail.com> | 2019-02-05 09:06:08 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-02-07 09:18:31 +0300 |
commit | 29e74d4952b772f7f1bf51e1a8f1665bbbde39d1 (patch) | |
tree | 211a7131ae8f0fa7d8d5f65422cd53ad0741de33 /benchmark/http | |
parent | d310d8df62f9c05d07e68c4177f225e9dda72271 (diff) |
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: https://github.com/nodejs/node/pull/25944
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/http')
-rw-r--r-- | benchmark/http/_chunky_http_client.js | 8 | ||||
-rw-r--r-- | benchmark/http/check_invalid_header_char.js | 4 | ||||
-rw-r--r-- | benchmark/http/check_is_http_token.js | 2 | ||||
-rw-r--r-- | benchmark/http/chunked.js | 8 | ||||
-rw-r--r-- | benchmark/http/client-request-body.js | 6 | ||||
-rw-r--r-- | benchmark/http/cluster.js | 6 | ||||
-rw-r--r-- | benchmark/http/end-vs-write-end.js | 6 | ||||
-rw-r--r-- | benchmark/http/headers.js | 6 | ||||
-rw-r--r-- | benchmark/http/http_server_for_chunky_client.js | 6 | ||||
-rw-r--r-- | benchmark/http/set-header.js | 4 | ||||
-rw-r--r-- | benchmark/http/set_header.js | 2 | ||||
-rw-r--r-- | benchmark/http/simple.js | 4 | ||||
-rw-r--r-- | benchmark/http/upgrade.js | 8 |
13 files changed, 35 insertions, 35 deletions
diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js index 7728a5d06c6..21418a7c26b 100644 --- a/benchmark/http/_chunky_http_client.js +++ b/benchmark/http/_chunky_http_client.js @@ -54,11 +54,11 @@ function main({ len, n }) { const add = 11; var count = 0; const PIPE = process.env.PIPE_NAME; - var socket = net.connect(PIPE, function() { + var socket = net.connect(PIPE, () => { bench.start(); WriteHTTPHeaders(socket, 1, len); socket.setEncoding('utf8'); - socket.on('data', function(d) { + socket.on('data', (d) => { var did = false; var pattern = 'HTTP/1.1 200 OK\r\n'; if ((d.length === pattern.length && d === pattern) || @@ -84,11 +84,11 @@ function main({ len, n }) { } } }); - socket.on('close', function() { + socket.on('close', () => { console.log('Connection closed'); }); - socket.on('error', function() { + socket.on('error', () => { throw new Error('Connection error'); }); }); diff --git a/benchmark/http/check_invalid_header_char.js b/benchmark/http/check_invalid_header_char.js index c70b0d39db2..46ca9f3d733 100644 --- a/benchmark/http/check_invalid_header_char.js +++ b/benchmark/http/check_invalid_header_char.js @@ -18,7 +18,7 @@ const groupedInputs = { 'sessionid=; Path=/', 'text/html; charset=utf-8', 'text/html; charset=utf-8', '10', 'W/"a-eda64de5"', 'OK', 'Express', 'Express', 'X-HTTP-Method-Override', 'sessionid=; Path=/', - 'application/json' + 'application/json', ], // Put it here so the benchmark result lines will not be super long. @@ -45,7 +45,7 @@ const inputs = [ // Invalid '中文呢', // unicode 'foo\nbar', - '\x7F' + '\x7F', ]; const bench = common.createBenchmark(main, { diff --git a/benchmark/http/check_is_http_token.js b/benchmark/http/check_is_http_token.js index c16993819be..eab075249e6 100644 --- a/benchmark/http/check_is_http_token.js +++ b/benchmark/http/check_is_http_token.js @@ -35,7 +35,7 @@ const bench = common.createBenchmark(main, { '中文呢', // unicode '((((())))', // invalid ':alternate-protocol', // fast bailout - 'alternate-protocol:' // slow bailout + 'alternate-protocol:', // slow bailout ], n: [1e6], }); diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js index 5615395ee0b..52b4605715c 100644 --- a/benchmark/http/chunked.js +++ b/benchmark/http/chunked.js @@ -20,21 +20,21 @@ function main({ len, n, c }) { const http = require('http'); const chunk = Buffer.alloc(len, '8'); - const server = http.createServer(function(req, res) { + const server = http.createServer((req, res) => { function send(left) { if (left === 0) return res.end(); res.write(chunk); - setTimeout(function() { + setTimeout(() => { send(left - 1); }, 0); } send(n); }); - server.listen(common.PORT, function() { + server.listen(common.PORT, () => { bench.http({ connections: c - }, function() { + }, () => { server.close(); }); }); diff --git a/benchmark/http/client-request-body.js b/benchmark/http/client-request-body.js index 49bb9130ae3..b5ac2828c6f 100644 --- a/benchmark/http/client-request-body.js +++ b/benchmark/http/client-request-body.js @@ -37,17 +37,17 @@ function main({ dur, len, type, method }) { method: 'POST' }; - const server = http.createServer(function(req, res) { + const server = http.createServer((req, res) => { res.end(); }); - server.listen(options.port, options.host, function() { + server.listen(options.port, options.host, () => { setTimeout(done, dur * 1000); bench.start(); pummel(); }); function pummel() { - const req = http.request(options, function(res) { + const req = http.request(options, (res) => { nreqs++; pummel(); // Line up next request. res.resume(); diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 667e826f163..35d0ba98d00 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -21,18 +21,18 @@ function main({ type, len, c }) { const w1 = cluster.fork(); const w2 = cluster.fork(); - cluster.on('listening', function() { + cluster.on('listening', () => { workers++; if (workers < 2) return; - setImmediate(function() { + setImmediate(() => { const path = `/${type}/${len}`; bench.http({ path: path, connections: c - }, function() { + }, () => { w1.destroy(); w2.destroy(); }); diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js index f839e5c3cd9..b4ca560b9a8 100644 --- a/benchmark/http/end-vs-write-end.js +++ b/benchmark/http/end-vs-write-end.js @@ -43,14 +43,14 @@ function main({ len, type, method, c }) { const fn = method === 'write' ? write : end; - const server = http.createServer(function(req, res) { + const server = http.createServer((req, res) => { fn(res); }); - server.listen(common.PORT, function() { + server.listen(common.PORT, () => { bench.http({ connections: c - }, function() { + }, () => { server.close(); }); }); diff --git a/benchmark/http/headers.js b/benchmark/http/headers.js index 748865afbf3..60d800c20cf 100644 --- a/benchmark/http/headers.js +++ b/benchmark/http/headers.js @@ -21,15 +21,15 @@ function main({ duplicates, n }) { } } - const server = http.createServer(function(req, res) { + const server = http.createServer((req, res) => { res.writeHead(200, headers); res.end(); }); - server.listen(common.PORT, function() { + server.listen(common.PORT, () => { bench.http({ path: '/', connections: 10 - }, function() { + }, () => { server.close(); }); }); diff --git a/benchmark/http/http_server_for_chunky_client.js b/benchmark/http/http_server_for_chunky_client.js index 1e5a4583669..edcacf5d124 100644 --- a/benchmark/http/http_server_for_chunky_client.js +++ b/benchmark/http/http_server_for_chunky_client.js @@ -12,7 +12,7 @@ tmpdir.refresh(); var server; -server = http.createServer(function(req, res) { +server = http.createServer((req, res) => { const headers = { 'content-type': 'text/plain', 'content-length': '2' @@ -21,7 +21,7 @@ server = http.createServer(function(req, res) { res.end('ok'); }); -server.on('error', function(err) { +server.on('error', (err) => { throw new Error(`server error: ${err}`); }); server.listen(PIPE); @@ -31,7 +31,7 @@ const child = fork( process.argv.slice(2) ); child.on('message', common.sendResult); -child.on('close', function(code) { +child.on('close', (code) => { server.close(); assert.strictEqual(code, 0); }); diff --git a/benchmark/http/set-header.js b/benchmark/http/set-header.js index f0987f2cc77..01cd8492dff 100644 --- a/benchmark/http/set-header.js +++ b/benchmark/http/set-header.js @@ -19,13 +19,13 @@ function main({ res }) { process.env.PORT = PORT; var server = require('../fixtures/simple-http-server.js') .listen(PORT) - .on('listening', function() { + .on('listening', () => { const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`; bench.http({ path: path, connections: c - }, function() { + }, () => { server.close(); }); }); diff --git a/benchmark/http/set_header.js b/benchmark/http/set_header.js index 22de61b3f84..4129e4fee0c 100644 --- a/benchmark/http/set_header.js +++ b/benchmark/http/set_header.js @@ -11,7 +11,7 @@ const bench = common.createBenchmark(main, { 'Content-Type', 'Content-Length', 'Connection', - 'Transfer-Encoding' + 'Transfer-Encoding', ], n: [1e6], }); diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 6d1851c45e1..c6faaaa9efd 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -13,13 +13,13 @@ const bench = common.createBenchmark(main, { function main({ type, len, chunks, c, chunkedEnc, res }) { var server = require('../fixtures/simple-http-server.js') .listen(common.PORT) - .on('listening', function() { + .on('listening', () => { const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`; bench.http({ path: path, connections: c - }, function() { + }, () => { server.close(); }); }); diff --git a/benchmark/http/upgrade.js b/benchmark/http/upgrade.js index 6b39323396a..c286cdb2644 100644 --- a/benchmark/http/upgrade.js +++ b/benchmark/http/upgrade.js @@ -21,14 +21,14 @@ const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + function main({ n }) { var server = require('../fixtures/simple-http-server.js') .listen(common.PORT) - .on('listening', function() { + .on('listening', () => { bench.start(); - doBench(server.address(), n, function() { + doBench(server.address(), n, () => { bench.end(n); server.close(); }); }) - .on('upgrade', function(req, socket, upgradeHead) { + .on('upgrade', (req, socket, upgradeHead) => { socket.resume(); socket.write(resData); socket.end(); @@ -45,7 +45,7 @@ function doBench(address, count, done) { conn.write(reqData); conn.resume(); - conn.on('end', function() { + conn.on('end', () => { doBench(address, count - 1, done); }); } |