mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
cd71838675
Fixes: https://github.com/nodejs/node/issues/50571 PR-URL: https://github.com/nodejs/node/pull/50938 Refs: https://github.com/nodejs/node/issues/50571 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
43 lines
868 B
JavaScript
43 lines
868 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
encoding: ['utf-8', 'latin1', 'iso-8859-3'],
|
|
ignoreBOM: [0, 1],
|
|
fatal: [0, 1],
|
|
len: [256, 1024 * 16, 1024 * 128],
|
|
n: [1e3],
|
|
type: ['SharedArrayBuffer', 'ArrayBuffer', 'Buffer'],
|
|
});
|
|
|
|
function main({ encoding, len, n, ignoreBOM, type, fatal }) {
|
|
const decoder = new TextDecoder(encoding, { ignoreBOM, fatal });
|
|
let buf;
|
|
|
|
switch (type) {
|
|
case 'SharedArrayBuffer': {
|
|
buf = new SharedArrayBuffer(len);
|
|
break;
|
|
}
|
|
case 'ArrayBuffer': {
|
|
buf = new ArrayBuffer(len);
|
|
break;
|
|
}
|
|
case 'Buffer': {
|
|
buf = Buffer.allocUnsafe(len);
|
|
break;
|
|
}
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
try {
|
|
decoder.decode(buf);
|
|
} catch {
|
|
// eslint-disable no-empty
|
|
}
|
|
}
|
|
bench.end(n);
|
|
}
|