summaryrefslogtreecommitdiff
path: root/benchmark/assert/deepequal-typedarrays.js
blob: 50e6e525b20a0c831b9c7492f0e3cc1eee738987 (plain)
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
44
'use strict';
const common = require('../common.js');
const assert = require('assert');

const bench = common.createBenchmark(main, {
  type: [
    'Int8Array',
    'Uint8Array',
    'Int16Array',
    'Uint16Array',
    'Int32Array',
    'Uint32Array',
    'Float32Array',
    'Float64Array',
    'Uint8ClampedArray',
  ],
  n: [1],
  method: [
    'deepEqual',
    'deepStrictEqual',
    'notDeepEqual',
    'notDeepStrictEqual'
  ],
  len: [1e6]
});

function main({ type, n, len, method }) {
  const clazz = global[type];
  const actual = new clazz(len);
  const expected = new clazz(len);
  const expectedWrong = Buffer.alloc(len);
  const wrongIndex = Math.floor(len / 2);
  expectedWrong[wrongIndex] = 123;

  // eslint-disable-next-line no-restricted-properties
  const fn = method !== '' ? assert[method] : assert.deepEqual;
  const value2 = method.includes('not') ? expectedWrong : expected;

  bench.start();
  for (var i = 0; i < n; ++i) {
    fn(actual, value2);
  }
  bench.end(n);
}