From 7acb1b17b13781346ca2591546966753b3f067f0 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 12:46:23 +0100 Subject: [PATCH 01/11] benchmark: add `no-var` rule in .eslintrc.yaml --- benchmark/.eslintrc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/benchmark/.eslintrc.yaml b/benchmark/.eslintrc.yaml index 7de962dc9002af..8ce0f9f6e148c1 100644 --- a/benchmark/.eslintrc.yaml +++ b/benchmark/.eslintrc.yaml @@ -5,6 +5,7 @@ env: es6: true rules: + no-var: error comma-dangle: - error - arrays: 'always-multiline' From 425373722c56c0e80aebea6e6e9680dab3b2e0a5 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 12:47:44 +0100 Subject: [PATCH 02/11] benchmark: use const instead of var in async_hooks --- benchmark/async_hooks/async-resource-vs-destroy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/async_hooks/async-resource-vs-destroy.js b/benchmark/async_hooks/async-resource-vs-destroy.js index 4464dd5f93e7de..a9cd60200e3149 100644 --- a/benchmark/async_hooks/async-resource-vs-destroy.js +++ b/benchmark/async_hooks/async-resource-vs-destroy.js @@ -55,7 +55,7 @@ function buildCurrentResource(getServe) { } function init(asyncId, type, triggerAsyncId, resource) { - var cr = executionAsyncResource(); + const cr = executionAsyncResource(); if (cr !== null) { resource[cls] = cr[cls]; } From 1162d9c847fd0458887dffd319b79ee80e5de87b Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 12:48:46 +0100 Subject: [PATCH 03/11] benchmark: use let instead of var in common.js --- benchmark/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/common.js b/benchmark/common.js index c5791c2bacfd5d..1ab7e263f7ed2b 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -227,7 +227,7 @@ function formatResult(data) { conf += ` ${key}=${JSON.stringify(data.conf[key])}`; } - var rate = data.rate.toString().split('.'); + let rate = data.rate.toString().split('.'); rate[0] = rate[0].replace(/(\d)(?=(?:\d\d\d)+(?!\d))/g, '$1,'); rate = (rate[1] ? rate.join('.') : rate[0]); return `${data.name}${conf}: ${rate}`; From 3e0e71b1a30de3d2d164f2602b82972cda8b9725 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 13:02:27 +0100 Subject: [PATCH 04/11] benchmark: use let instead of var in dns --- benchmark/dns/lookup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/dns/lookup.js b/benchmark/dns/lookup.js index 164e490bd3bc24..691daa8a879e2b 100644 --- a/benchmark/dns/lookup.js +++ b/benchmark/dns/lookup.js @@ -10,7 +10,7 @@ const bench = common.createBenchmark(main, { }); function main({ name, n, all }) { - var i = 0; + let i = 0; if (all === 'true') { const opts = { all: true }; From 295111d62af9551d2bc8f282a1def97c3d8f014d Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 13:04:46 +0100 Subject: [PATCH 05/11] benchmark: use let instead of var in run.js --- benchmark/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/run.js b/benchmark/run.js index 8e81a2c5e16ab7..07da6c547f551c 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -60,7 +60,7 @@ if (format === 'csv') { conf = conf.replace(/"/g, '""'); console.log(`"${data.name}", "${conf}", ${data.rate}, ${data.time}`); } else { - var rate = data.rate.toString().split('.'); + let rate = data.rate.toString().split('.'); rate[0] = rate[0].replace(/(\d)(?=(?:\d\d\d)+(?!\d))/g, '$1,'); rate = (rate[1] ? rate.join('.') : rate[0]); console.log(`${data.name} ${conf}: ${rate}`); From 08cf2390dd2eaf6e513d7414d56b75fc4a121a0b Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 13:13:58 +0100 Subject: [PATCH 06/11] benchmark: use let instead of var in timers --- benchmark/timers/immediate.js | 10 +++++----- benchmark/timers/timers-breadth-args.js | 2 +- benchmark/timers/timers-breadth.js | 2 +- benchmark/timers/timers-cancel-pooled.js | 4 ++-- benchmark/timers/timers-cancel-unpooled.js | 5 ++--- benchmark/timers/timers-depth.js | 2 +- benchmark/timers/timers-insert-unpooled.js | 5 ++--- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/benchmark/timers/immediate.js b/benchmark/timers/immediate.js index d12106a0e030fc..3bd4c097dce5a0 100644 --- a/benchmark/timers/immediate.js +++ b/benchmark/timers/immediate.js @@ -31,7 +31,7 @@ function main({ n, type }) { // setImmediate tail recursion, 0 arguments function depth(N) { - var n = 0; + let n = 0; bench.start(); setImmediate(cb); function cb() { @@ -45,7 +45,7 @@ function depth(N) { // setImmediate tail recursion, 1 argument function depth1(N) { - var n = 0; + let n = 0; bench.start(); setImmediate(cb, 1); function cb(a1) { @@ -59,7 +59,7 @@ function depth1(N) { // Concurrent setImmediate, 0 arguments function breadth(N) { - var n = 0; + let n = 0; bench.start(); function cb() { n++; @@ -73,7 +73,7 @@ function breadth(N) { // Concurrent setImmediate, 1 argument function breadth1(N) { - var n = 0; + let n = 0; bench.start(); function cb(a1) { n++; @@ -88,7 +88,7 @@ function breadth1(N) { // Concurrent setImmediate, 4 arguments function breadth4(N) { N /= 2; - var n = 0; + let n = 0; bench.start(); function cb(a1, a2, a3, a4) { n++; diff --git a/benchmark/timers/timers-breadth-args.js b/benchmark/timers/timers-breadth-args.js index 63a301dc9bc7dc..bf1727ab865b6d 100644 --- a/benchmark/timers/timers-breadth-args.js +++ b/benchmark/timers/timers-breadth-args.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var j = 0; + let j = 0; function cb1(arg1) { j++; if (j === n) diff --git a/benchmark/timers/timers-breadth.js b/benchmark/timers/timers-breadth.js index 78bd5a97ae84b8..7af5d380018898 100644 --- a/benchmark/timers/timers-breadth.js +++ b/benchmark/timers/timers-breadth.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var j = 0; + let j = 0; bench.start(); function cb() { j++; diff --git a/benchmark/timers/timers-cancel-pooled.js b/benchmark/timers/timers-cancel-pooled.js index 5045983210263e..30dbd7bc007d7a 100644 --- a/benchmark/timers/timers-cancel-pooled.js +++ b/benchmark/timers/timers-cancel-pooled.js @@ -8,11 +8,11 @@ const bench = common.createBenchmark(main, { function main({ n }) { - var timer = setTimeout(() => {}, 1); + let timer = setTimeout(() => {}, 1); for (let i = 0; i < n; i++) { setTimeout(cb, 1); } - var next = timer._idlePrev; + let next = timer._idlePrev; clearTimeout(timer); bench.start(); diff --git a/benchmark/timers/timers-cancel-unpooled.js b/benchmark/timers/timers-cancel-unpooled.js index df203ee4810b1d..70f8fd96c9cbf1 100644 --- a/benchmark/timers/timers-cancel-unpooled.js +++ b/benchmark/timers/timers-cancel-unpooled.js @@ -14,14 +14,13 @@ function main({ n, direction }) { timersList.push(setTimeout(cb, i + 1)); } - var j; bench.start(); if (direction === 'start') { - for (j = 0; j < n; j++) { + for (let j = 0; j < n; j++) { clearTimeout(timersList[j]); } } else { - for (j = n - 1; j >= 0; j--) { + for (let j = n - 1; j >= 0; j--) { clearTimeout(timersList[j]); } } diff --git a/benchmark/timers/timers-depth.js b/benchmark/timers/timers-depth.js index bfc6dd02cf5c65..766733ba1862a9 100644 --- a/benchmark/timers/timers-depth.js +++ b/benchmark/timers/timers-depth.js @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, { }); function main({ n }) { - var i = 0; + let i = 0; bench.start(); setTimeout(cb, 1); function cb() { diff --git a/benchmark/timers/timers-insert-unpooled.js b/benchmark/timers/timers-insert-unpooled.js index 11d25d5fe79670..5ee255b5e15fd2 100644 --- a/benchmark/timers/timers-insert-unpooled.js +++ b/benchmark/timers/timers-insert-unpooled.js @@ -10,14 +10,13 @@ const bench = common.createBenchmark(main, { function main({ direction, n }) { const timersList = []; - var i; bench.start(); if (direction === 'start') { - for (i = 1; i <= n; i++) { + for (let i = 1; i <= n; i++) { timersList.push(setTimeout(cb, i)); } } else { - for (i = n; i > 0; i--) { + for (let i = n; i > 0; i--) { timersList.push(setTimeout(cb, i)); } } From 0991d53be9ee5b04a8f2c349f428211721a206a9 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 14:17:20 +0100 Subject: [PATCH 07/11] benchmark: use let instead of var in tls --- benchmark/tls/convertprotocols.js | 2 +- benchmark/tls/throughput.js | 10 +++++----- benchmark/tls/tls-connect.js | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmark/tls/convertprotocols.js b/benchmark/tls/convertprotocols.js index 74bb942bfcec4f..87c447436a44db 100644 --- a/benchmark/tls/convertprotocols.js +++ b/benchmark/tls/convertprotocols.js @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, { function main({ n }) { const input = ['ABC', 'XYZ123', 'FOO']; - var m = {}; + let m = {}; // First call dominates results if (n > 1) { tls.convertALPNProtocols(input, m); diff --git a/benchmark/tls/throughput.js b/benchmark/tls/throughput.js index a8f2d19649d04a..da26eba177b2cf 100644 --- a/benchmark/tls/throughput.js +++ b/benchmark/tls/throughput.js @@ -7,12 +7,12 @@ const bench = common.createBenchmark(main, { }); const fixtures = require('../../test/common/fixtures'); -var options; +let options; const tls = require('tls'); function main({ dur, type, size }) { - var encoding; - var chunk; + let encoding; + let chunk; switch (type) { case 'buf': chunk = Buffer.alloc(size, 'b'); @@ -37,7 +37,7 @@ function main({ dur, type, size }) { }; const server = tls.createServer(options, onConnection); - var conn; + let conn; server.listen(common.PORT, () => { const opt = { port: common.PORT, rejectUnauthorized: false }; conn = tls.connect(opt, () => { @@ -52,7 +52,7 @@ function main({ dur, type, size }) { } }); - var received = 0; + let received = 0; function onConnection(conn) { conn.on('data', (chunk) => { received += chunk.length; diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index 1cb04d98a52721..3fc2ecb614978b 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -8,11 +8,11 @@ const bench = common.createBenchmark(main, { dur: [5] }); -var clientConn = 0; -var serverConn = 0; -var dur; -var concurrency; -var running = true; +let clientConn = 0; +let serverConn = 0; +let dur; +let concurrency; +let running = true; function main(conf) { dur = conf.dur; From 98849b8fea5f7fbb87157376aa329a61d52bec94 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 14:32:11 +0100 Subject: [PATCH 08/11] benchmark: use let instead of var in url --- benchmark/url/legacy-vs-whatwg-url-parse.js | 10 +++++----- benchmark/url/legacy-vs-whatwg-url-serialize.js | 6 +++--- benchmark/url/whatwg-url-properties.js | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmark/url/legacy-vs-whatwg-url-parse.js b/benchmark/url/legacy-vs-whatwg-url-parse.js index 6e5e25d231242f..94115d1305bb95 100644 --- a/benchmark/url/legacy-vs-whatwg-url-parse.js +++ b/benchmark/url/legacy-vs-whatwg-url-parse.js @@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, { function useLegacy(data) { const len = data.length; - var result = url.parse(data[0]); // Avoid dead code elimination + let result = url.parse(data[0]); // Avoid dead code elimination bench.start(); for (let i = 0; i < len; ++i) { result = url.parse(data[i]); @@ -24,7 +24,7 @@ function useLegacy(data) { function useWHATWGWithBase(data) { const len = data.length; - var result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination + let result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination bench.start(); for (let i = 0; i < len; ++i) { const item = data[i]; @@ -36,7 +36,7 @@ function useWHATWGWithBase(data) { function useWHATWGWithoutBase(data) { const len = data.length; - var result = new URL(data[0]); // Avoid dead code elimination + let result = new URL(data[0]); // Avoid dead code elimination bench.start(); for (let i = 0; i < len; ++i) { result = new URL(data[i]); @@ -47,8 +47,8 @@ function useWHATWGWithoutBase(data) { function main({ e, method, type, withBase }) { withBase = withBase === 'true'; - var noDead; // Avoid dead code elimination. - var data; + let noDead; // Avoid dead code elimination. + let data; switch (method) { case 'legacy': data = common.bakeUrlData(type, e, false, false); diff --git a/benchmark/url/legacy-vs-whatwg-url-serialize.js b/benchmark/url/legacy-vs-whatwg-url-serialize.js index 5523e549ceb233..e3254ede3acee8 100644 --- a/benchmark/url/legacy-vs-whatwg-url-serialize.js +++ b/benchmark/url/legacy-vs-whatwg-url-serialize.js @@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, { function useLegacy(data) { const obj = url.parse(data[0]); const len = data.length; - var noDead = url.format(obj); + let noDead = url.format(obj); bench.start(); for (let i = 0; i < len; i++) { noDead = data[i].toString(); @@ -25,7 +25,7 @@ function useLegacy(data) { function useWHATWG(data) { const obj = new URL(data[0]); const len = data.length; - var noDead = obj.toString(); + let noDead = obj.toString(); bench.start(); for (let i = 0; i < len; i++) { noDead = data[i].toString(); @@ -37,7 +37,7 @@ function useWHATWG(data) { function main({ type, e, method }) { const data = common.bakeUrlData(type, e, false, false); - var noDead; // Avoid dead code elimination. + let noDead; // Avoid dead code elimination. switch (method) { case 'legacy': noDead = useLegacy(data); diff --git a/benchmark/url/whatwg-url-properties.js b/benchmark/url/whatwg-url-properties.js index ac71ff4f636d66..f0ba2931e51f1e 100644 --- a/benchmark/url/whatwg-url-properties.js +++ b/benchmark/url/whatwg-url-properties.js @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, { function setAndGet(data, prop) { const len = data.length; - var result = data[0][prop]; + let result = data[0][prop]; bench.start(); for (let i = 0; i < len; ++i) { result = data[i][prop]; @@ -24,7 +24,7 @@ function setAndGet(data, prop) { function get(data, prop) { const len = data.length; - var result = data[0][prop]; + let result = data[0][prop]; bench.start(); for (let i = 0; i < len; ++i) { result = data[i][prop]; // get From 4444d3b08d21120c6866d0c080d5239919986216 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 14:43:01 +0100 Subject: [PATCH 09/11] benchmark: use let instead of var in util --- benchmark/util/inspect-array.js | 8 ++++---- benchmark/util/inspect.js | 2 +- benchmark/util/normalize-encoding.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js index 4fd73785f789d1..f78b1d92420df5 100644 --- a/benchmark/util/inspect-array.js +++ b/benchmark/util/inspect-array.js @@ -15,8 +15,8 @@ const bench = common.createBenchmark(main, { }); function main({ n, len, type }) { - var arr = Array(len); - var i, opts; + let arr = Array(len); + let opts; switch (type) { case 'denseArray_showHidden': @@ -31,14 +31,14 @@ function main({ n, len, type }) { case 'sparseArray': break; case 'mixedArray': - for (i = 0; i < n; i += 2) + for (let i = 0; i < n; i += 2) arr[i] = i; break; default: throw new Error(`Unsupported type ${type}`); } bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { util.inspect(arr, opts); } bench.end(n); diff --git a/benchmark/util/inspect.js b/benchmark/util/inspect.js index 159d831f762884..0a19e65ea234be 100644 --- a/benchmark/util/inspect.js +++ b/benchmark/util/inspect.js @@ -37,7 +37,7 @@ function benchmark(n, obj, options) { } function main({ method, n, option }) { - var obj; + let obj; const options = opts[option]; switch (method) { case 'Object': diff --git a/benchmark/util/normalize-encoding.js b/benchmark/util/normalize-encoding.js index 464bda52f35c44..03769cb3b229cb 100644 --- a/benchmark/util/normalize-encoding.js +++ b/benchmark/util/normalize-encoding.js @@ -46,11 +46,11 @@ function getInput(input) { function main({ input, n }) { const { normalizeEncoding } = require('internal/util'); const inputs = getInput(input); - var noDead = ''; + let noDead = ''; bench.start(); - for (var i = 0; i < n; ++i) { - for (var j = 0; j < inputs.length; ++j) { + for (let i = 0; i < n; ++i) { + for (let j = 0; j < inputs.length; ++j) { noDead = normalizeEncoding(inputs[j]); } } From 58ab2547ce3cc9d513e6b4644371c9ab483eae59 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 14:51:09 +0100 Subject: [PATCH 10/11] benchmark: use let instead of var in worker --- benchmark/worker/echo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/worker/echo.js b/benchmark/worker/echo.js index 8d45a1f76b5eac..7988ffc7e121eb 100644 --- a/benchmark/worker/echo.js +++ b/benchmark/worker/echo.js @@ -55,7 +55,7 @@ function main({ n, workers, sendsPerBroadcast: sends, payload: payloadType }) { return; } for (const worker of workerObjs) { - for (var i = 0; i < sends; ++i) + for (let i = 0; i < sends; ++i) worker.postMessage(payload); } } From ce9f93e8ab8e5ff7ffaca00c536009b462ea494e Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Fri, 14 Feb 2020 14:59:09 +0100 Subject: [PATCH 11/11] benchmark: use let instead of var in zlib --- benchmark/zlib/creation.js | 5 ++--- benchmark/zlib/deflate.js | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/benchmark/zlib/creation.js b/benchmark/zlib/creation.js index 30e6afe6b4355f..c2d063c20d8d02 100644 --- a/benchmark/zlib/creation.js +++ b/benchmark/zlib/creation.js @@ -15,17 +15,16 @@ function main({ n, type, options }) { const fn = zlib[`create${type}`]; if (typeof fn !== 'function') throw new Error('Invalid zlib type'); - var i = 0; if (options === 'true') { const opts = {}; bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) fn(opts); bench.end(n); } else { bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) fn(); bench.end(n); } diff --git a/benchmark/zlib/deflate.js b/benchmark/zlib/deflate.js index 6d3bda90c6fdfa..5baedc924d4bc8 100644 --- a/benchmark/zlib/deflate.js +++ b/benchmark/zlib/deflate.js @@ -13,11 +13,11 @@ function main({ n, method, inputLen }) { method = method || 'deflate'; const chunk = Buffer.alloc(inputLen, 'a'); - var i = 0; switch (method) { // Performs `n` writes for a single deflate stream - case 'createDeflate': - var deflater = zlib.createDeflate(); + case 'createDeflate': { + let i = 0; + const deflater = zlib.createDeflate(); deflater.resume(); deflater.on('finish', () => { bench.end(n); @@ -30,9 +30,11 @@ function main({ n, method, inputLen }) { deflater.write(chunk, next); })(); break; + } // Performs `n` single deflate operations - case 'deflate': - var deflate = zlib.deflate; + case 'deflate': { + let i = 0; + const deflate = zlib.deflate; bench.start(); (function next(err, result) { if (i++ === n) @@ -40,14 +42,16 @@ function main({ n, method, inputLen }) { deflate(chunk, next); })(); break; + } // Performs `n` single deflateSync operations - case 'deflateSync': - var deflateSync = zlib.deflateSync; + case 'deflateSync': { + const deflateSync = zlib.deflateSync; bench.start(); - for (; i < n; ++i) + for (let i = 0; i < n; ++i) deflateSync(chunk); bench.end(n); break; + } default: throw new Error('Unsupported deflate method'); }