mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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>
This commit is contained in:
parent
75d25bc6db
commit
ccf05ef751
4 changed files with 125 additions and 9 deletions
20
benchmark/buffers/buffer-write-string-short.js
Normal file
20
benchmark/buffers/buffer-write-string-short.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
'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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue