From 093ecfa8dced3900a93cce16b30ea43c69667bc4 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Wed, 19 Jan 2022 19:58:11 +0200 Subject: [PATCH] benchmark: add `subarray` to `buffer-slice` PR-URL: https://github.com/nodejs/node/pull/41596 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel --- benchmark/buffers/buffer-slice.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js index a64cbd2ab2db7c..dcb18754e8420d 100644 --- a/benchmark/buffers/buffer-slice.js +++ b/benchmark/buffers/buffer-slice.js @@ -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); }