test: fix long-running buffer benchmarks
PR-URL: https://github.com/nodejs/node/pull/20125 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
e5f53206dd
commit
a2cf005cef
@ -3,12 +3,12 @@
|
|||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
|
charsPerLine: [76],
|
||||||
|
linesCount: [8 << 16],
|
||||||
n: [32],
|
n: [32],
|
||||||
});
|
});
|
||||||
|
|
||||||
function main({ n }) {
|
function main({ charsPerLine, linesCount, n }) {
|
||||||
const charsPerLine = 76;
|
|
||||||
const linesCount = 8 << 16;
|
|
||||||
const bytesCount = charsPerLine * linesCount / 4 * 3;
|
const bytesCount = charsPerLine * linesCount / 4 * 3;
|
||||||
|
|
||||||
const line = `${'abcd'.repeat(charsPerLine / 4)}\n`;
|
const line = `${'abcd'.repeat(charsPerLine / 4)}\n`;
|
||||||
|
@ -4,10 +4,11 @@ const common = require('../common.js');
|
|||||||
|
|
||||||
const bench = common.createBenchmark(main, {
|
const bench = common.createBenchmark(main, {
|
||||||
n: [32],
|
n: [32],
|
||||||
|
size: [8 << 20]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main({ n }) {
|
function main({ n, size }) {
|
||||||
const s = 'abcd'.repeat(8 << 20);
|
const s = 'abcd'.repeat(size);
|
||||||
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
|
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
|
||||||
s.match(/./); // Flatten string.
|
s.match(/./); // Flatten string.
|
||||||
assert.strictEqual(s.length % 4, 0);
|
assert.strictEqual(s.length % 4, 0);
|
||||||
|
@ -25,10 +25,10 @@ const bench = common.createBenchmark(main, {
|
|||||||
search: searchStrings,
|
search: searchStrings,
|
||||||
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
|
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
|
||||||
type: ['buffer', 'string'],
|
type: ['buffer', 'string'],
|
||||||
iter: [100000]
|
n: [100000]
|
||||||
});
|
});
|
||||||
|
|
||||||
function main({ iter, search, encoding, type }) {
|
function main({ n, search, encoding, type }) {
|
||||||
var aliceBuffer = fs.readFileSync(
|
var aliceBuffer = fs.readFileSync(
|
||||||
path.resolve(__dirname, '../fixtures/alice.html')
|
path.resolve(__dirname, '../fixtures/alice.html')
|
||||||
);
|
);
|
||||||
@ -46,8 +46,8 @@ function main({ iter, search, encoding, type }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (var i = 0; i < iter; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
aliceBuffer.indexOf(search, 0, encoding);
|
aliceBuffer.indexOf(search, 0, encoding);
|
||||||
}
|
}
|
||||||
bench.end(iter);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,11 @@ runBenchmark('buffers',
|
|||||||
'args=1',
|
'args=1',
|
||||||
'buffer=fast',
|
'buffer=fast',
|
||||||
'byteLength=1',
|
'byteLength=1',
|
||||||
|
'charsPerLine=6',
|
||||||
'encoding=utf8',
|
'encoding=utf8',
|
||||||
'endian=BE',
|
'endian=BE',
|
||||||
'len=2',
|
'len=2',
|
||||||
|
'linesCount=1',
|
||||||
'method=',
|
'method=',
|
||||||
'n=1',
|
'n=1',
|
||||||
'pieces=1',
|
'pieces=1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user