• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4const assert = require('assert');
5
6const bench = common.createBenchmark(main, {
7  n: [5e3],
8  size: [1e2, 1e3, 5e4],
9  strict: [0, 1],
10  method: ['deepEqual', 'notDeepEqual'],
11});
12
13function createObj(source, add = '') {
14  return source.map((n) => ({
15    foo: 'yarp',
16    nope: {
17      bar: `123${add}`,
18      a: [1, 2, 3],
19      baz: n,
20      c: {},
21      b: [],
22    },
23  }));
24}
25
26function main({ size, n, method, strict }) {
27  const len = Math.min(Math.ceil(n / size), 20);
28
29  const source = Array.apply(null, Array(size));
30  const actual = createObj(source);
31  const expected = createObj(source);
32  const expectedWrong = createObj(source, '4');
33
34  if (strict) {
35    method = method.replace('eep', 'eepStrict');
36  }
37  const fn = assert[method];
38  const value2 = method.includes('not') ? expectedWrong : expected;
39
40  bench.start();
41  for (let i = 0; i < len; ++i) {
42    fn(actual, value2);
43  }
44  bench.end(len);
45}
46