mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

This commits reverts da69d13623
PR-URL: https://github.com/nodejs/node/pull/58220
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
24 lines
529 B
JavaScript
24 lines
529 B
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const { Buffer } = require('buffer');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
type: ['fast', 'slow', 'subarray'],
|
|
n: [1e6],
|
|
});
|
|
|
|
const buf = Buffer.allocUnsafe(1024);
|
|
const slowBuf = Buffer.allocUnsafeSlow(1024);
|
|
|
|
function main({ n, type }) {
|
|
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++) {
|
|
fn();
|
|
}
|
|
bench.end(n);
|
|
}
|