From 1ed312a73736a0a2b7afc3824e69fd4b89be74a2 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 17 Oct 2022 15:00:31 +0300 Subject: [PATCH] benchmark: add blob benchmark PR-URL: https://github.com/nodejs/node/pull/44990 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- benchmark/blob/blob.js | 30 +++++++++++++++++++++++++++ test/benchmark/test-benchmark-blob.js | 7 +++++++ 2 files changed, 37 insertions(+) create mode 100644 benchmark/blob/blob.js create mode 100644 test/benchmark/test-benchmark-blob.js diff --git a/benchmark/blob/blob.js b/benchmark/blob/blob.js new file mode 100644 index 00000000000000..e63a18c84830ce --- /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: [128, 1024, 1024 ** 2], + 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); +} 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 });