2017-07-18 18:00:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
2018-05-30 05:50:31 +02:00
|
|
|
const { deepEqual, deepStrictEqual, notDeepEqual, notDeepStrictEqual } =
|
|
|
|
require('assert');
|
2017-07-18 18:00:44 +02:00
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [5e2],
|
|
|
|
len: [5e2],
|
2018-08-03 15:30:22 +02:00
|
|
|
strict: [0, 1],
|
2017-07-18 18:00:44 +02:00
|
|
|
method: [
|
|
|
|
'deepEqual_primitiveOnly',
|
|
|
|
'deepEqual_objectOnly',
|
|
|
|
'deepEqual_mixed',
|
|
|
|
'notDeepEqual_primitiveOnly',
|
|
|
|
'notDeepEqual_objectOnly',
|
2019-02-01 06:05:17 +01:00
|
|
|
'notDeepEqual_mixed',
|
|
|
|
],
|
2017-07-18 18:00:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function benchmark(method, n, values, values2) {
|
|
|
|
const actual = new Set(values);
|
|
|
|
// Prevent reference equal elements
|
|
|
|
const deepCopy = JSON.parse(JSON.stringify(values2 ? values2 : values));
|
|
|
|
const expected = new Set(deepCopy);
|
|
|
|
bench.start();
|
2019-11-12 19:56:03 +01:00
|
|
|
for (let i = 0; i < n; ++i) {
|
2017-07-18 18:00:44 +02:00
|
|
|
method(actual, expected);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|
|
|
|
|
2018-08-03 15:30:22 +02:00
|
|
|
function main({ n, len, method, strict }) {
|
2017-07-18 18:00:44 +02:00
|
|
|
const array = Array(len).fill(1);
|
|
|
|
|
2017-12-30 03:54:30 +01:00
|
|
|
switch (method) {
|
2017-09-03 23:06:09 +02:00
|
|
|
case '':
|
|
|
|
// Empty string falls through to next line as default, mostly for tests.
|
2019-11-12 19:56:03 +01:00
|
|
|
case 'deepEqual_primitiveOnly': {
|
|
|
|
const values = array.map((_, i) => `str_${i}`);
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
|
|
|
case 'deepEqual_objectOnly': {
|
|
|
|
const values = array.map((_, i) => [`str_${i}`, null]);
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
|
|
|
case 'deepEqual_mixed': {
|
|
|
|
const values = array.map((_, i) => {
|
2017-07-18 18:00:44 +02:00
|
|
|
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
|
|
|
|
});
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? deepStrictEqual : deepEqual, n, values);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
|
|
|
case 'notDeepEqual_primitiveOnly': {
|
|
|
|
const values = array.map((_, i) => `str_${i}`);
|
|
|
|
const values2 = values.slice(0);
|
2017-07-18 18:00:44 +02:00
|
|
|
values2[Math.floor(len / 2)] = 'w00t';
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
|
|
|
case 'notDeepEqual_objectOnly': {
|
|
|
|
const values = array.map((_, i) => [`str_${i}`, null]);
|
|
|
|
const values2 = values.slice(0);
|
2017-07-18 18:00:44 +02:00
|
|
|
values2[Math.floor(len / 2)] = ['w00t'];
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
|
|
|
case 'notDeepEqual_mixed': {
|
|
|
|
const values = array.map((_, i) => {
|
2017-07-18 18:00:44 +02:00
|
|
|
return i % 2 ? [`str_${i}`, null] : `str_${i}`;
|
|
|
|
});
|
2019-11-12 19:56:03 +01:00
|
|
|
const values2 = values.slice();
|
2017-07-18 18:00:44 +02:00
|
|
|
values2[0] = 'w00t';
|
2018-08-03 15:30:22 +02:00
|
|
|
benchmark(strict ? notDeepStrictEqual : notDeepEqual, n, values, values2);
|
2017-07-18 18:00:44 +02:00
|
|
|
break;
|
2019-11-12 19:56:03 +01:00
|
|
|
}
|
2017-07-18 18:00:44 +02:00
|
|
|
default:
|
2018-01-23 13:17:21 +01:00
|
|
|
throw new Error(`Unsupported method "${method}"`);
|
2017-07-18 18:00:44 +02:00
|
|
|
}
|
|
|
|
}
|