forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeepequal-object.js
43 lines (37 loc) · 952 Bytes
/
deepequal-object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
n: [25, 2e2],
size: [1e2, 1e4],
method: ['deepEqual', 'notDeepEqual', 'deepStrictEqual', 'notDeepStrictEqual'],
}, {
combinationFilter: (p) => {
return p.size === 1e4 && p.n === 25 ||
p.size === 1e3 && p.n === 2e2 ||
p.size === 1e2 && p.n === 2e3 ||
p.size === 1;
},
});
function createObj(size, add = '') {
return Array.from({ length: size }, (n) => ({
foo: 'yarp',
nope: {
bar: `123${add}`,
a: [1, 2, 3],
baz: n,
c: {},
b: [],
},
}));
}
function main({ size, n, method }) {
const fn = assert[method];
const actual = createObj(size);
const expected = method.includes('not') ? createObj(size, '4') : createObj(size);
bench.start();
for (let i = 0; i < n; ++i) {
fn(actual, expected);
}
bench.end(n);
}