mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
43ddf7631e
PR-URL: https://github.com/nodejs/node/pull/46616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
23 lines
542 B
JavaScript
23 lines
542 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
len: [2, 16, 256], // x16
|
|
n: [4e6],
|
|
});
|
|
|
|
function main({ n, len }) {
|
|
const data = Buffer.alloc(len * 16, 'a');
|
|
const expected = Buffer.byteLength(data, 'buffer');
|
|
let changed = false;
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
const actual = Buffer.byteLength(data, 'buffer');
|
|
if (expected !== actual) { changed = true; }
|
|
}
|
|
bench.end(n);
|
|
if (changed) {
|
|
throw new Error('Result changed during iteration');
|
|
}
|
|
}
|