node/benchmark/assert/deepequal-object.js
MrJithil 217acb9036
benchmark: avoid input param manipulation
PR-URL: https://github.com/nodejs/node/pull/41741
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-02-05 08:26:37 -08:00

46 lines
968 B
JavaScript

'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [5e3],
size: [1e2, 1e3, 5e4],
strict: [0, 1],
method: ['deepEqual', 'notDeepEqual'],
});
function createObj(source, add = '') {
return source.map((n) => ({
foo: 'yarp',
nope: {
bar: `123${add}`,
a: [1, 2, 3],
baz: n,
c: {},
b: [],
},
}));
}
function main({ size, n, method, strict }) {
const len = Math.min(Math.ceil(n / size), 20);
const source = Array.apply(null, Array(size));
const actual = createObj(source);
const expected = createObj(source);
const expectedWrong = createObj(source, '4');
if (strict) {
method = method.replace('eep', 'eepStrict');
}
const fn = assert[method];
const value2 = method.includes('not') ? expectedWrong : expected;
bench.start();
for (let i = 0; i < len; ++i) {
fn(actual, value2);
}
bench.end(len);
}