Skip to content
Permalink
Browse files

benchmark: use let instead of var in crypto

PR-URL: #31135
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
dnlup authored and BridgeAR committed Dec 30, 2019
1 parent b657a64 commit b193142e0a623834ae724284d26314c79f9fc164
@@ -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);
@@ -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;
@@ -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++)
@@ -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')
@@ -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);
@@ -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);
}

0 comments on commit b193142

Please sign in to comment.
You can’t perform that action at this time.