Skip to content

Commit

Permalink
benchmark: add subarray to buffer-slice
Browse files Browse the repository at this point in the history
PR-URL: #41596
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
benjamingr authored and aduh95 committed Jan 21, 2022
1 parent 830cbca commit 6bf769e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions benchmark/buffers/buffer-slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ const common = require('../common.js');
const SlowBuffer = require('buffer').SlowBuffer;

const bench = common.createBenchmark(main, {
type: ['fast', 'slow'],
type: ['fast', 'slow', 'subarray'],
n: [1e6]
});

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);
}

0 comments on commit 6bf769e

Please sign in to comment.