Skip to content
Permalink
Browse files

benchmark: use let instead of var in assert

PR-URL: #30450
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
dnlup authored and MylesBorins committed Nov 12, 2019
1 parent ec49ea7 commit 351ee645c82457c1edc8c345bcad536b3c50cf5a
@@ -27,7 +27,7 @@ function main({ len, n, method, strict }) {
const value2 = method.includes('not') ? expectedWrong : expected;

bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
fn(actual, value2);
}
bench.end(n);
@@ -24,49 +24,58 @@ function benchmark(method, n, values, values2) {
const deepCopy = JSON.parse(JSON.stringify(values2 ? values2 : values));
const expected = new Map(deepCopy);
bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
method(actual, expected);
}
bench.end(n);
}

function main({ n, len, method, strict }) {
const array = Array(len).fill(1);
var values, values2;

switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly':
values = array.map((_, i) => [`str_${i}`, 123]);
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => [`str_${i}`, 123]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'deepEqual_objectOnly':
values = array.map((_, i) => [[`str_${i}`, 1], 123]);
}
case 'deepEqual_objectOnly': {
const values = array.map((_, i) => [[`str_${i}`, 1], 123]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'deepEqual_mixed':
values = array.map((_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123]);
}
case 'deepEqual_mixed': {
const values = array.map(
(_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123]
);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'notDeepEqual_primitiveOnly':
values = array.map((_, i) => [`str_${i}`, 123]);
values2 = values.slice(0);
}
case 'notDeepEqual_primitiveOnly': {
const values = array.map((_, i) => [`str_${i}`, 123]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t', 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
case 'notDeepEqual_objectOnly':
values = array.map((_, i) => [[`str_${i}`, 1], 123]);
values2 = values.slice(0);
}
case 'notDeepEqual_objectOnly': {
const values = array.map((_, i) => [[`str_${i}`, 1], 123]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = [['w00t'], 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
case 'notDeepEqual_mixed':
values = array.map((_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123]);
values2 = values.slice(0);
}
case 'notDeepEqual_mixed': {
const values = array.map(
(_, i) => [i % 2 ? [`str_${i}`, 1] : `str_${i}`, 123]
);
const values2 = values.slice(0);
values2[0] = ['w00t', 123];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
}
default:
throw new Error(`Unsupported method ${method}`);
}
@@ -42,7 +42,7 @@ function main({ size, n, method, strict }) {
const value2 = method.includes('not') ? expectedWrong : expected;

bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
fn(actual, value2);
}
bench.end(n);
@@ -26,7 +26,7 @@ const bench = common.createBenchmark(main, {

function run(fn, n, actual, expected) {
bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
@@ -38,7 +38,7 @@ function main({ n, len, primitive, method, strict }) {
const expected = [];
const expectedWrong = [];

for (var x = 0; x < len; x++) {
for (let x = 0; x < len; x++) {
actual.push(prim);
expected.push(prim);
expectedWrong.push(prim);
@@ -31,7 +31,7 @@ function main({ n, primitive, method, strict }) {
const value2 = method.includes('not') ? expectedWrong : expected;

bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
fn([actual], [value2]);
}
bench.end(n);
@@ -24,7 +24,7 @@ function benchmark(method, n, values, values2) {
const deepCopy = JSON.parse(JSON.stringify(values2 ? values2 : values));
const expected = new Set(deepCopy);
bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
method(actual, expected);
}
bench.end(n);
@@ -33,45 +33,49 @@ function benchmark(method, n, values, values2) {
function main({ n, len, method, strict }) {
const array = Array(len).fill(1);

var values, values2;

switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
case 'deepEqual_primitiveOnly': {
const values = array.map((_, i) => `str_${i}`);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'deepEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
}
case 'deepEqual_objectOnly': {
const values = array.map((_, i) => [`str_${i}`, null]);
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'deepEqual_mixed':
values = array.map((_, i) => {
}
case 'deepEqual_mixed': {
const values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
break;
case 'notDeepEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
values2 = values.slice(0);
}
case 'notDeepEqual_primitiveOnly': {
const values = array.map((_, i) => `str_${i}`);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = 'w00t';
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
case 'notDeepEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
values2 = values.slice(0);
}
case 'notDeepEqual_objectOnly': {
const values = array.map((_, i) => [`str_${i}`, null]);
const values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t'];
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
case 'notDeepEqual_mixed':
values = array.map((_, i) => {
}
case 'notDeepEqual_mixed': {
const values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
values2 = values.slice();
const values2 = values.slice();
values2[0] = 'w00t';
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
break;
}
default:
throw new Error(`Unsupported method "${method}"`);
}
@@ -36,7 +36,7 @@ function main({ type, n, len, method, strict }) {
const value2 = method.includes('not') ? expectedWrong : expected;

bench.start();
for (var i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
actual[0] = i;
value2[0] = i;
fn(actual, value2);
@@ -6,9 +6,8 @@ const assert = require('assert');
const bench = common.createBenchmark(main, { n: [1e5] });

function main({ n }) {
var i;
bench.start();
for (i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
if (i % 2 === 0)
assert(true);
else
@@ -13,28 +13,27 @@ function main({ n, method }) {
const doNotThrowError = () => { return 'foobar'; };
const regExp = /foobar/;
const message = 'failure';
var i;

switch (method) {
case '':
// Empty string falls through to next line as default, mostly for tests.
case 'doesNotThrow':
bench.start();
for (i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
doesNotThrow(doNotThrowError);
}
bench.end(n);
break;
case 'throws_TypeError':
bench.start();
for (i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
throws(throwError, TypeError, message);
}
bench.end(n);
break;
case 'throws_RegExp':
bench.start();
for (i = 0; i < n; ++i) {
for (let i = 0; i < n; ++i) {
throws(throwError, regExp, message);
}
bench.end(n);

0 comments on commit 351ee64

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