From d30911e51b36e0bf519cf1c42c2dbd9d175e123f Mon Sep 17 00:00:00 2001 From: dnlup Date: Mon, 30 Dec 2019 12:20:07 +0100 Subject: [PATCH] benchmark: use let instead of var in crypto PR-URL: https://github.com/nodejs/node/pull/31135 Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat Reviewed-By: Rich Trott --- benchmark/crypto/aes-gcm-throughput.js | 2 +- benchmark/crypto/cipher-stream.js | 12 ++++++------ benchmark/crypto/get-ciphers.js | 2 +- benchmark/crypto/hash-stream-creation.js | 6 +++--- benchmark/crypto/hash-stream-throughput.js | 4 ++-- benchmark/crypto/rsa-encrypt-decrypt-throughput.js | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index cd8f29c8c7d7b2..b1b08c481700ea 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -25,7 +25,7 @@ function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { const bits = written * 8; const mbits = bits / (1024 * 1024); - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { const alice = crypto.createCipheriv(cipher, key, iv); alice.setAAD(associate_data); const enc = alice.update(message); diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index f426a32769d0dd..4bb1695e2d20cc 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -38,8 +38,8 @@ function main({ api, cipher, type, len, writes }) { const alice_cipher = crypto.createCipher(cipher, alice_secret); const bob_cipher = crypto.createDecipher(cipher, bob_secret); - var message; - var encoding; + let message; + let encoding; switch (type) { case 'asc': message = 'a'.repeat(len); @@ -65,7 +65,7 @@ function main({ api, cipher, type, len, writes }) { } function streamWrite(alice, bob, message, encoding, writes) { - var written = 0; + let written = 0; bob.on('data', (c) => { written += c.length; }); @@ -86,9 +86,9 @@ function streamWrite(alice, bob, message, encoding, writes) { } function legacyWrite(alice, bob, message, encoding, writes) { - var written = 0; - var enc, dec; - for (var i = 0; i < writes; i++) { + let written = 0; + let enc, dec; + for (let i = 0; i < writes; i++) { enc = alice.update(message, encoding); dec = bob.update(enc); written += dec.length; diff --git a/benchmark/crypto/get-ciphers.js b/benchmark/crypto/get-ciphers.js index 5bbe0915311484..1bf910a6a80ba3 100644 --- a/benchmark/crypto/get-ciphers.js +++ b/benchmark/crypto/get-ciphers.js @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, { function main({ n, v }) { const method = require(v).getCiphers; - var i = 0; + let i = 0; // First call to getCiphers will dominate the results if (n > 1) { for (; i < n; i++) diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js index 0a98eb1471c9d4..c21eb6eaaaed99 100644 --- a/benchmark/crypto/hash-stream-creation.js +++ b/benchmark/crypto/hash-stream-creation.js @@ -20,8 +20,8 @@ function main({ api, type, len, out, writes, algo }) { api = 'legacy'; } - var message; - var encoding; + let message; + let encoding; switch (type) { case 'asc': message = 'a'.repeat(len); @@ -52,7 +52,7 @@ function legacyWrite(algo, message, encoding, writes, len, outEnc) { while (writes-- > 0) { const h = crypto.createHash(algo); h.update(message, encoding); - var res = h.digest(outEnc); + let res = h.digest(outEnc); // Include buffer creation costs for older versions if (outEnc === 'buffer' && typeof res === 'string') diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js index 52be3d4caf8501..b86d70604616b5 100644 --- a/benchmark/crypto/hash-stream-throughput.js +++ b/benchmark/crypto/hash-stream-throughput.js @@ -19,8 +19,8 @@ function main({ api, type, len, algo, writes }) { api = 'legacy'; } - var message; - var encoding; + let message; + let encoding; switch (type) { case 'asc': message = 'a'.repeat(len); diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js index 13153c20cad569..9791160263c9ec 100644 --- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js +++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js @@ -35,7 +35,7 @@ function StreamWrite(algo, keylen, message, n, len) { const privateKey = RSA_PrivatePem[keylen]; const publicKey = RSA_PublicPem[keylen]; - for (var i = 0; i < n; i++) { + for (let i = 0; i < n; i++) { const enc = crypto.privateEncrypt(privateKey, message); crypto.publicDecrypt(publicKey, enc); }