From a8dd6f5dd2e19f39a6f5d873e069bd4e0128bc31 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 13 Oct 2022 16:48:36 +0300 Subject: [PATCH 1/3] benchmark: add blob benchmark --- benchmark/blob/blob.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 benchmark/blob/blob.js diff --git a/benchmark/blob/blob.js b/benchmark/blob/blob.js new file mode 100644 index 00000000000000..c6e430607192a8 --- /dev/null +++ b/benchmark/blob/blob.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common.js'); +const { Blob } = require('buffer'); + +const bench = common.createBenchmark(main, { + bytes: [0, 128, 512, 1024], + n: [1e6], + operation: ['text', 'arrayBuffer'] +}); + +async function run(n, bytes, operation) { + const buff = Buffer.allocUnsafe(bytes); + const source = new Blob(buff); + bench.start(); + for (let i = 0; i < n; i++) { + switch (operation) { + case 'text': + await source.text(); + break; + case 'arrayBuffer': + await source.arrayBuffer(); + break; + } + } + bench.end(n); +} + +function main(conf) { + run(conf.n, conf.bytes, conf.operation).catch(console.log); +} From c4a7560f4085779784ab028593d810f1e011cbe8 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 13 Oct 2022 17:48:19 +0300 Subject: [PATCH 2/3] test: add blob benchmark --- test/benchmark/test-benchmark-blob.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/benchmark/test-benchmark-blob.js diff --git a/test/benchmark/test-benchmark-blob.js b/test/benchmark/test-benchmark-blob.js new file mode 100644 index 00000000000000..e49ed4b4ae939c --- /dev/null +++ b/test/benchmark/test-benchmark-blob.js @@ -0,0 +1,7 @@ +'use strict'; + +require('../common'); + +const runBenchmark = require('../common/benchmark'); + +runBenchmark('blob', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); From a32f9796c8c072f50bbb155f660e65569bd7efff Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 13 Oct 2022 18:16:41 +0300 Subject: [PATCH 3/3] benchmark: update blob byte values --- benchmark/blob/blob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/blob/blob.js b/benchmark/blob/blob.js index c6e430607192a8..e63a18c84830ce 100644 --- a/benchmark/blob/blob.js +++ b/benchmark/blob/blob.js @@ -3,7 +3,7 @@ const common = require('../common.js'); const { Blob } = require('buffer'); const bench = common.createBenchmark(main, { - bytes: [0, 128, 512, 1024], + bytes: [128, 1024, 1024 ** 2], n: [1e6], operation: ['text', 'arrayBuffer'] });