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

const bench = common.createBenchmark(main, {
  type: [
    'Int8Array',
    'Uint8Array',
    'Float32Array',
    'Float64Array',
    'Uint8ClampedArray',
  ],
  n: [5e2],
  strict: [0, 1],
  method: [
    'deepEqual',
    'notDeepEqual',
  ],
  len: [1e2, 5e3]
});

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

  if (strict) {
    method = method.replace('eep', 'eepStrict');
  }
  const fn = assert[method];
  const value2 = method.includes('not') ? expectedWrong : expected;

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