Skip to content

Commit d24e409

Browse files
addaleaxevanlucas
authored andcommitted
benchmark: add benchmark for Buffer.concat
PR-URL: #7054 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent e8c91e7 commit d24e409

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

benchmark/buffers/buffer-concat.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
pieces: [1, 4, 16],
6+
pieceSize: [1, 16, 256],
7+
withTotalLength: [0, 1],
8+
n: [1024]
9+
});
10+
11+
function main(conf) {
12+
const n = +conf.n;
13+
const size = +conf.pieceSize;
14+
const pieces = +conf.pieces;
15+
16+
const list = new Array(pieces);
17+
list.fill(Buffer.allocUnsafe(size));
18+
19+
const totalLength = conf.withTotalLength ? pieces * size : undefined;
20+
21+
bench.start();
22+
for (var i = 0; i < n * 1024; i++) {
23+
Buffer.concat(list, totalLength);
24+
}
25+
bench.end(n);
26+
}

0 commit comments

Comments
 (0)