benchmark: adjust configuration for string-decoder bench

According to https://github.com/nodejs/node/pull/59186 this
benchmark file takes 6 hours to complete a full benchmark/compare.js
script (60 runs in total) and this regression tests unrealitics to do
between Node.js releases. By using calibrate-n scripts I could find
a better N also ajusting some bench configs. e.g: avoid dead code
elimination by V8.

PR-URL: https://github.com/nodejs/node/pull/59187
Refs: https://github.com/nodejs/node/pull/59186
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Rafael Gonzaga 2025-07-25 17:49:56 -03:00 committed by GitHub
parent 345a550fa1
commit daa9e4bb8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,11 +1,12 @@
'use strict';
const common = require('../common.js');
const StringDecoder = require('string_decoder').StringDecoder;
const assert = require('node:assert');
const bench = common.createBenchmark(main, {
encoding: ['ascii', 'utf8', 'base64-utf8', 'base64-ascii', 'utf16le'],
inLen: [32, 128, 1024, 4096],
chunkLen: [16, 64, 256, 1024],
inLen: [32, 128, 1024],
chunkLen: [16, 256, 1024],
n: [25e5],
});
@ -75,10 +76,13 @@ function main({ encoding, inLen, chunkLen, n }) {
const nChunks = chunks.length;
let avoidDeadCode;
bench.start();
for (let i = 0; i < n; ++i) {
avoidDeadCode = '';
for (let j = 0; j < nChunks; ++j)
sd.write(chunks[j]);
avoidDeadCode += sd.write(chunks[j]);
}
bench.end(n);
assert.ok(avoidDeadCode);
}