Skip to content

Commit

Permalink
test: fix long-running buffer benchmarks
Browse files Browse the repository at this point in the history
PR-URL: #20125
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
apapirovski authored and jasnell committed Apr 23, 2018
1 parent 2883454 commit c61db33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions benchmark/buffers/buffer-base64-decode-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const common = require('../common.js');

const bench = common.createBenchmark(main, {
charsPerLine: [76],
linesCount: [8 << 16],
n: [32],
});

function main({ n }) {
const charsPerLine = 76;
const linesCount = 8 << 16;
function main({ charsPerLine, linesCount, n }) {
const bytesCount = charsPerLine * linesCount / 4 * 3;

const line = `${'abcd'.repeat(charsPerLine / 4)}\n`;
Expand Down
5 changes: 3 additions & 2 deletions benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const common = require('../common.js');

const bench = common.createBenchmark(main, {
n: [32],
size: [8 << 20]
});

function main({ n }) {
const s = 'abcd'.repeat(8 << 20);
function main({ n, size }) {
const s = 'abcd'.repeat(size);
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
s.match(/./); // Flatten string.
assert.strictEqual(s.length % 4, 0);
Expand Down
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const bench = common.createBenchmark(main, {
search: searchStrings,
encoding: ['undefined', 'utf8', 'ucs2', 'binary'],
type: ['buffer', 'string'],
iter: [100000]
n: [100000]
});

function main({ iter, search, encoding, type }) {
function main({ n, search, encoding, type }) {
var aliceBuffer = fs.readFileSync(
path.resolve(__dirname, '../fixtures/alice.html')
);
Expand All @@ -46,8 +46,8 @@ function main({ iter, search, encoding, type }) {
}

bench.start();
for (var i = 0; i < iter; i++) {
for (var i = 0; i < n; i++) {
aliceBuffer.indexOf(search, 0, encoding);
}
bench.end(iter);
bench.end(n);
}
2 changes: 2 additions & 0 deletions test/sequential/test-benchmark-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ runBenchmark('buffers',
'args=1',
'buffer=fast',
'byteLength=1',
'charsPerLine=6',
'encoding=utf8',
'endian=BE',
'len=2',
'linesCount=1',
'method=',
'n=1',
'pieces=1',
Expand Down

0 comments on commit c61db33

Please sign in to comment.