1'use strict';
2const common = require('../common.js');
3const SlowBuffer = require('buffer').SlowBuffer;
4
5const bench = common.createBenchmark(main, {
6  type: ['fast', 'slow', 'subarray'],
7  n: [1e6],
8});
9
10const buf = Buffer.allocUnsafe(1024);
11const slowBuf = new SlowBuffer(1024);
12
13function main({ n, type }) {
14  const b = type === 'slow' ? slowBuf : buf;
15  const fn = type === 'subarray' ?
16    () => b.subarray(10, 256) :
17    () => b.slice(10, 256);
18
19  bench.start();
20  for (let i = 0; i < n; i++) {
21    fn();
22  }
23  bench.end(n);
24}
25