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 <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 danielleadams committed Apr 21, 2022
1 parent e46c7d6 commit 3d4df9c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions benchmark/buffers/buffer-slice.js
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 3d4df9c

Please sign in to comment.