Skip to content

Commit

Permalink
benchmark: add subarray to buffer-slice
Browse files Browse the repository at this point in the history
PR-URL: nodejs#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>
  • Loading branch information
benjamingr authored and Linkgoron committed Jan 31, 2022
1 parent fe6aa80 commit 093ecfa
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 093ecfa

Please sign in to comment.