node/benchmark/buffers/buffer-write-string-short.js
Robert Nagy ccf05ef751
buffer: use fast API for writing one-byte strings
PR-URL: https://github.com/nodejs/node/pull/54310
PR-URL: https://github.com/nodejs/node/pull/54311
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-08-15 01:01:05 +00:00

21 lines
432 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
encoding: [
'utf8', 'ascii', 'latin1',
],
len: [1, 8, 16, 32],
n: [1e6],
});
function main({ len, n, encoding }) {
const buf = Buffer.allocUnsafe(len);
const string = Buffer.from('a'.repeat(len)).toString();
bench.start();
for (let i = 0; i < n; ++i) {
buf.write(string, 0, encoding);
}
bench.end(n);
}