Skip to content

Commit

Permalink
benchmark: use let instead of var in crypto
Browse files Browse the repository at this point in the history
PR-URL: #31135
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
dnlup authored and BridgeAR committed Jan 3, 2020
1 parent b657a64 commit b193142
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions benchmark/crypto/cipher-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
});
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/crypto/get-ciphers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
6 changes: 3 additions & 3 deletions benchmark/crypto/hash-stream-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions benchmark/crypto/hash-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/crypto/rsa-encrypt-decrypt-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b193142

Please sign in to comment.