Skip to content

Commit

Permalink
benchmark: refactor deepequal-set
Browse files Browse the repository at this point in the history
This is a minor refactor of benchmark/assert/deepequal-set.js to
reduce exceptions that need to be made for lint compliance.

PR-URL: #21030
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Jun 6, 2018
1 parent 56c6759 commit 686587b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions benchmark/assert/deepequal-set.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict';

/* eslint-disable no-restricted-properties */

const common = require('../common.js');
const assert = require('assert');
const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } =
require('assert');

const bench = common.createBenchmark(main, {
n: [5e2],
Expand Down Expand Up @@ -48,82 +47,82 @@ function main({ n, len, method }) {
// Empty string falls through to next line as default, mostly for tests.
case 'deepEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
benchmark(assert.deepEqual, n, values);
benchmark(deepEqual, n, values);
break;
case 'deepStrictEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
benchmark(assert.deepStrictEqual, n, values);
benchmark(deepStrictEqual, n, values);
break;
case 'deepEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
benchmark(assert.deepEqual, n, values);
benchmark(deepEqual, n, values);
break;
case 'deepStrictEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
benchmark(assert.deepStrictEqual, n, values);
benchmark(deepStrictEqual, n, values);
break;
case 'deepEqual_mixed':
values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
benchmark(assert.deepEqual, n, values);
benchmark(deepEqual, n, values);
break;
case 'deepStrictEqual_mixed':
values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
benchmark(assert.deepStrictEqual, n, values);
benchmark(deepStrictEqual, n, values);
break;
case 'deepEqual_looseMatches':
values = array.map((_, i) => i);
values2 = values.slice().map((v) => String(v));
benchmark(assert.deepEqual, n, values, values2);
benchmark(deepEqual, n, values, values2);
break;
case 'notDeepEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
values2 = values.slice(0);
values2[Math.floor(len / 2)] = 'w00t';
benchmark(assert.notDeepEqual, n, values, values2);
benchmark(notDeepEqual, n, values, values2);
break;
case 'notDeepStrictEqual_primitiveOnly':
values = array.map((_, i) => `str_${i}`);
values2 = values.slice(0);
values2[Math.floor(len / 2)] = 'w00t';
benchmark(assert.notDeepStrictEqual, n, values, values2);
benchmark(notDeepStrictEqual, n, values, values2);
break;
case 'notDeepEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t'];
benchmark(assert.notDeepEqual, n, values, values2);
benchmark(notDeepEqual, n, values, values2);
break;
case 'notDeepStrictEqual_objectOnly':
values = array.map((_, i) => [`str_${i}`, null]);
values2 = values.slice(0);
values2[Math.floor(len / 2)] = ['w00t'];
benchmark(assert.notDeepStrictEqual, n, values, values2);
benchmark(notDeepStrictEqual, n, values, values2);
break;
case 'notDeepEqual_mixed':
values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
values2 = values.slice();
values2[0] = 'w00t';
benchmark(assert.notDeepEqual, n, values, values2);
benchmark(notDeepEqual, n, values, values2);
break;
case 'notDeepStrictEqual_mixed':
values = array.map((_, i) => {
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
});
values2 = values.slice();
values2[0] = 'w00t';
benchmark(assert.notDeepStrictEqual, n, values, values2);
benchmark(notDeepStrictEqual, n, values, values2);
break;
case 'notDeepEqual_looseMatches':
values = array.map((_, i) => i);
values2 = values.slice().map((v) => String(v));
values2[len - 1] = String(len + 1);
benchmark(assert.notDeepEqual, n, values, values2);
benchmark(notDeepEqual, n, values, values2);
break;
default:
throw new Error(`Unsupported method "${method}"`);
Expand Down

0 comments on commit 686587b

Please sign in to comment.