summaryrefslogtreecommitdiff
path: root/benchmark/buffers/buffer-concat.js
blob: ced0f4ff31ce8d5a3495570af78077ad33e056f4 (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, {
  pieces: [4, 16],
  pieceSize: [1, 16, 256],
  withTotalLength: [0, 1],
  n: [8e5]
});

function main({ n, pieces, pieceSize, withTotalLength }) {
  const list = Array.from({ length: pieces })
    .fill(Buffer.allocUnsafe(pieceSize));

  const totalLength = withTotalLength ? pieces * pieceSize : undefined;

  bench.start();
  for (var i = 0; i < n; i++) {
    Buffer.concat(list, totalLength);
  }
  bench.end(n);
}