benchmark: add subarray
to buffer-slice
PR-URL: https://github.com/nodejs/node/pull/41596 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
830cbca810
commit
6bf769e4e6
@ -3,7 +3,7 @@ const common = require('../common.js');
|
||||
const SlowBuffer = require('buffer').SlowBuffer;
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
type: ['fast', 'slow'],
|
||||
type: ['fast', 'slow', 'subarray'],
|
||||
n: [1e6]
|
||||
});
|
||||
|
||||
@ -11,10 +11,14 @@ const buf = Buffer.allocUnsafe(1024);
|
||||
const slowBuf = new SlowBuffer(1024);
|
||||
|
||||
function main({ n, type }) {
|
||||
const b = type === 'fast' ? buf : slowBuf;
|
||||
const b = type === 'slow' ? slowBuf : buf;
|
||||
const fn = type === 'subarray' ?
|
||||
() => b.subarray(10, 256) :
|
||||
() => b.slice(10, 256);
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < n; i++) {
|
||||
b.slice(10, 256);
|
||||
fn();
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user