From b6ddbc12918bc21ba45fb35f6cb0bb7d1ac06ded Mon Sep 17 00:00:00 2001 From: dnlup Date: Fri, 13 Dec 2019 18:43:41 +0100 Subject: [PATCH] benchmark: use let/const instead of var in buffers PR-URL: https://github.com/nodejs/node/pull/30945 Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- benchmark/buffers/buffer-bytelength.js | 4 ++-- .../buffers/buffer-compare-instance-method.js | 11 +++++------ benchmark/buffers/buffer-hex.js | 5 ++--- benchmark/buffers/buffer-indexof.js | 2 +- benchmark/buffers/buffer-iterate.js | 8 ++++---- benchmark/buffers/buffer-swap.js | 4 ++-- benchmark/buffers/buffer-tostring.js | 9 ++++----- benchmark/buffers/buffer-write-string.js | 14 ++++++-------- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index 3246a42d96b34c..1b324a49f89de8 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -16,8 +16,8 @@ const chars = [ ]; function main({ n, len, encoding }) { - var strings = []; - var results = [ len * 16 ]; + let strings = []; + let results = [ len * 16 ]; if (encoding === 'buffer') { strings = [ Buffer.alloc(len * 16, 'a') ]; } else { diff --git a/benchmark/buffers/buffer-compare-instance-method.js b/benchmark/buffers/buffer-compare-instance-method.js index 284001c236d99d..eb18fa518037f4 100644 --- a/benchmark/buffers/buffer-compare-instance-method.js +++ b/benchmark/buffers/buffer-compare-instance-method.js @@ -12,7 +12,6 @@ function main({ n, size, args }) { const b1 = Buffer.alloc(size, 'a'); const b0Len = b0.length; const b1Len = b1.length; - var i; b1[size - 1] = 'b'.charCodeAt(0); @@ -20,7 +19,7 @@ function main({ n, size, args }) { case 2: b0.compare(b1, 0); bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { b0.compare(b1, 0); } bench.end(n); @@ -28,7 +27,7 @@ function main({ n, size, args }) { case 3: b0.compare(b1, 0, b1Len); bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { b0.compare(b1, 0, b1Len); } bench.end(n); @@ -36,7 +35,7 @@ function main({ n, size, args }) { case 4: b0.compare(b1, 0, b1Len, 0); bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { b0.compare(b1, 0, b1Len, 0); } bench.end(n); @@ -44,7 +43,7 @@ function main({ n, size, args }) { case 5: b0.compare(b1, 0, b1Len, 0, b0Len); bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { b0.compare(b1, 0, b1Len, 0, b0Len); } bench.end(n); @@ -52,7 +51,7 @@ function main({ n, size, args }) { default: b0.compare(b1); bench.start(); - for (i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { b0.compare(b1); } bench.end(n); diff --git a/benchmark/buffers/buffer-hex.js b/benchmark/buffers/buffer-hex.js index 1b49ca745381da..33d2b44d6a5950 100644 --- a/benchmark/buffers/buffer-hex.js +++ b/benchmark/buffers/buffer-hex.js @@ -9,16 +9,15 @@ const bench = common.createBenchmark(main, { function main({ len, n }) { const buf = Buffer.alloc(len); - var i; - for (i = 0; i < buf.length; i++) + for (let i = 0; i < buf.length; i++) buf[i] = i & 0xff; const hex = buf.toString('hex'); bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) Buffer.from(hex, 'hex'); bench.end(n); diff --git a/benchmark/buffers/buffer-indexof.js b/benchmark/buffers/buffer-indexof.js index e635da2351c4a7..4c0993a1ef0ef9 100644 --- a/benchmark/buffers/buffer-indexof.js +++ b/benchmark/buffers/buffer-indexof.js @@ -25,7 +25,7 @@ const bench = common.createBenchmark(main, { }); function main({ n, search, encoding, type }) { - var aliceBuffer = fs.readFileSync( + let aliceBuffer = fs.readFileSync( path.resolve(__dirname, '../fixtures/alice.html') ); diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index e81ce2b3035d90..de002108a95d65 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -29,15 +29,15 @@ function main({ size, type, method, n }) { } function benchFor(buffer, n) { - for (var k = 0; k < n; k++) { - for (var i = 0; i < buffer.length; i++) { + for (let k = 0; k < n; k++) { + for (let i = 0; i < buffer.length; i++) { assert(buffer[i] === 0); } } } function benchForOf(buffer, n) { - for (var k = 0; k < n; k++) { + for (let k = 0; k < n; k++) { for (const b of buffer) { assert(b === 0); } @@ -45,7 +45,7 @@ function benchForOf(buffer, n) { } function benchIterator(buffer, n) { - for (var k = 0; k < n; k++) { + for (let k = 0; k < n; k++) { const iter = buffer[Symbol.iterator](); let cur = iter.next(); diff --git a/benchmark/buffers/buffer-swap.js b/benchmark/buffers/buffer-swap.js index d22bf2fd5504ea..a33bac4ae3ed78 100644 --- a/benchmark/buffers/buffer-swap.js +++ b/benchmark/buffers/buffer-swap.js @@ -36,7 +36,7 @@ Buffer.prototype.htons = function htons() { Buffer.prototype.htonl = function htonl() { if (this.length % 4 !== 0) throw new RangeError(); - for (var i = 0; i < this.length; i += 4) { + for (let i = 0; i < this.length; i += 4) { swap(this, i, i + 3); swap(this, i + 1, i + 2); } @@ -66,7 +66,7 @@ function createBuffer(len, aligned) { function genMethod(method) { const fnString = ` return function ${method}(n, buf) { - for (var i = 0; i <= n; i++) + for (let i = 0; i <= n; i++) buf.${method}(); }`; return (new Function(fnString))(); diff --git a/benchmark/buffers/buffer-tostring.js b/benchmark/buffers/buffer-tostring.js index 88543d8fd3af5a..98d6ab3fa08311 100644 --- a/benchmark/buffers/buffer-tostring.js +++ b/benchmark/buffers/buffer-tostring.js @@ -15,29 +15,28 @@ function main({ encoding, args, len, n }) { if (encoding.length === 0) encoding = undefined; - var i; switch (args) { case 1: bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) buf.toString(encoding); bench.end(n); break; case 2: bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) buf.toString(encoding, 0); bench.end(n); break; case 3: bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) buf.toString(encoding, 0, len); bench.end(n); break; default: bench.start(); - for (i = 0; i < n; i += 1) + for (let i = 0; i < n; i += 1) buf.toString(); bench.end(n); break; diff --git a/benchmark/buffers/buffer-write-string.js b/benchmark/buffers/buffer-write-string.js index b30edcf8867adf..cd24d379728cda 100644 --- a/benchmark/buffers/buffer-write-string.js +++ b/benchmark/buffers/buffer-write-string.js @@ -15,21 +15,19 @@ function main({ len, n, encoding, args }) { let start = 0; const buf = Buffer.allocUnsafe(len); - var i; - switch (args) { case 'offset': string = 'a'.repeat(Math.floor(len / 2)); start = len - string.length; if (encoding) { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string, start, encoding); } bench.end(n); } else { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string, start); } bench.end(n); @@ -39,13 +37,13 @@ function main({ len, n, encoding, args }) { string = 'a'.repeat(len); if (encoding) { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string, 0, buf.length, encoding); } bench.end(n); } else { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string, 0, buf.length); } bench.end(n); @@ -55,13 +53,13 @@ function main({ len, n, encoding, args }) { string = 'a'.repeat(len); if (encoding) { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string, encoding); } bench.end(n); } else { bench.start(); - for (i = 0; i < n; ++i) { + for (let i = 0; i < n; ++i) { buf.write(string); } bench.end(n);