2016-02-20 01:03:16 +00:00
|
|
|
'use strict';
|
2017-09-14 01:48:53 +00:00
|
|
|
const common = require('../common.js');
|
|
|
|
const SlowBuffer = require('buffer').SlowBuffer;
|
2014-05-23 03:37:47 +00:00
|
|
|
|
2017-09-14 01:48:53 +00:00
|
|
|
const bench = common.createBenchmark(main, {
|
2022-01-19 17:58:11 +00:00
|
|
|
type: ['fast', 'slow', 'subarray'],
|
2023-02-04 18:19:25 +00:00
|
|
|
n: [1e6],
|
2014-05-23 03:37:47 +00:00
|
|
|
});
|
|
|
|
|
2017-09-14 01:48:53 +00:00
|
|
|
const buf = Buffer.allocUnsafe(1024);
|
|
|
|
const slowBuf = new SlowBuffer(1024);
|
2014-05-23 03:37:47 +00:00
|
|
|
|
2017-12-30 02:59:57 +00:00
|
|
|
function main({ n, type }) {
|
2022-01-19 17:58:11 +00:00
|
|
|
const b = type === 'slow' ? slowBuf : buf;
|
|
|
|
const fn = type === 'subarray' ?
|
|
|
|
() => b.subarray(10, 256) :
|
|
|
|
() => b.slice(10, 256);
|
|
|
|
|
2014-05-23 03:37:47 +00:00
|
|
|
bench.start();
|
2019-07-26 15:54:19 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
2022-01-19 17:58:11 +00:00
|
|
|
fn();
|
2014-05-23 03:37:47 +00:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|