From e62b30cf068ef84d71eae7cd948b5a8642a1066c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 29 May 2016 22:19:02 +0200 Subject: [PATCH 1/2] benchmark: add benchmark for Buffer.concat --- benchmark/buffers/buffer-concat.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmark/buffers/buffer-concat.js diff --git a/benchmark/buffers/buffer-concat.js b/benchmark/buffers/buffer-concat.js new file mode 100644 index 00000000000000..ff95e0a48aef6e --- /dev/null +++ b/benchmark/buffers/buffer-concat.js @@ -0,0 +1,23 @@ +'use strict'; +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + pieces: [1, 4, 16], + pieceSize: [1, 16, 256], + n: [1024] +}); + +function main(conf) { + const n = +conf.n; + const size = +conf.pieceSize; + const pieces = +conf.pieces; + + const list = new Array(pieces); + list.fill(Buffer.allocUnsafe(size)); + + bench.start(); + for (var i = 0; i < n * 1024; i++) { + Buffer.concat(list); + } + bench.end(n); +} From ef33ad008f64e97c0e7439e17b0edcc300fdad4e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 29 May 2016 22:44:00 +0200 Subject: [PATCH 2/2] [squash] add benchmarking with and without totalLength --- benchmark/buffers/buffer-concat.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/benchmark/buffers/buffer-concat.js b/benchmark/buffers/buffer-concat.js index ff95e0a48aef6e..a27e132193ef41 100644 --- a/benchmark/buffers/buffer-concat.js +++ b/benchmark/buffers/buffer-concat.js @@ -4,6 +4,7 @@ const common = require('../common.js'); const bench = common.createBenchmark(main, { pieces: [1, 4, 16], pieceSize: [1, 16, 256], + withTotalLength: [0, 1], n: [1024] }); @@ -15,9 +16,11 @@ function main(conf) { const list = new Array(pieces); list.fill(Buffer.allocUnsafe(size)); + const totalLength = conf.withTotalLength ? pieces * size : undefined; + bench.start(); for (var i = 0; i < n * 1024; i++) { - Buffer.concat(list); + Buffer.concat(list, totalLength); } bench.end(n); }