• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3
4const bench = common.createBenchmark(main, {
5  method: ['offset', 'slice'],
6  size: [16, 512, 4096, 16386],
7  n: [1e6]
8});
9
10function compareUsingSlice(b0, b1, len, iter) {
11  for (let i = 0; i < iter; i++)
12    Buffer.compare(b0.slice(1, len), b1.slice(1, len));
13}
14
15function compareUsingOffset(b0, b1, len, iter) {
16  for (let i = 0; i < iter; i++)
17    b0.compare(b1, 1, len, 1, len);
18}
19
20function main({ n, size, method }) {
21  const fn = method === 'slice' ? compareUsingSlice : compareUsingOffset;
22  bench.start();
23  fn(Buffer.alloc(size, 'a'),
24     Buffer.alloc(size, 'b'),
25     size >> 1,
26     n);
27  bench.end(n);
28}
29