aboutsummaryrefslogtreecommitdiff
path: root/benchmark/buffers/buffer-equals.js
blob: 99d2472bd3a088241f19dd504bf40163d42fe3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
const common = require('../common.js');

const bench = common.createBenchmark(main, {
  size: [0, 512, 16386],
  difflen: ['true', 'false'],
  n: [1e6]
});

function main({ n, size, difflen }) {
  const b0 = Buffer.alloc(size, 'a');
  const b1 = Buffer.alloc(size + (difflen === 'true' ? 1 : 0), 'a');

  if (b1.length > 0)
    b1[b1.length - 1] = 'b'.charCodeAt(0);

  bench.start();
  for (let i = 0; i < n; i++) {
    b0.equals(b1);
  }
  bench.end(n);
}