Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: use let instead of var in assert #30450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/assert/deepequal-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 26 additions & 17 deletions benchmark/assert/deepequal-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/assert/deepequal-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/assert/deepequal-prims-and-objs-big-array-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/assert/deepequal-prims-and-objs-big-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 22 additions & 18 deletions benchmark/assert/deepequal-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}"`);
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/assert/deepequal-typedarrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions benchmark/assert/ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions benchmark/assert/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down