summaryrefslogtreecommitdiff
path: root/benchmark/assert/deepequal-buffer.js
blob: 2a7d9e3bed7c38b9c6c882b38347b38132fb9779 (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
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
  n: [1e3],
  len: [1e2],
  method: ['strict', 'nonstrict']
});

function main(conf) {
  const n = +conf.n;
  const len = +conf.len;
  var i;

  const data = Buffer.allocUnsafe(len);
  const actual = Buffer.alloc(len);
  const expected = Buffer.alloc(len);
  data.copy(actual);
  data.copy(expected);

  switch (conf.method) {
    case 'strict':
      bench.start();
      for (i = 0; i < n; ++i) {
        // eslint-disable-next-line no-restricted-properties
        assert.deepEqual(actual, expected);
      }
      bench.end(n);
      break;
    case 'nonstrict':
      bench.start();
      for (i = 0; i < n; ++i) {
        assert.deepStrictEqual(actual, expected);
      }
      bench.end(n);
      break;
    default:
      throw new Error('Unsupported method');
  }
}