summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRafael Gonzaga <rafael.nunu@hotmail.com>2022-12-21 13:09:43 -0300
committerGitHub <noreply@github.com>2022-12-21 16:09:43 +0000
commit70d269de77705daa29ad77c6ffd1021c213c902a (patch)
tree1d29194ac2520e2937068f1063563513afd4016e /benchmark
parent42d3d7471733ae3f893205ffd18bdfbfcb9333c6 (diff)
downloadnode-new-70d269de77705daa29ad77c6ffd1021c213c902a.tar.gz
benchmark: include webstreams benchmark
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs/node/pull/45876 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/webstreams/creation.js49
-rw-r--r--benchmark/webstreams/pipe-to.js36
-rw-r--r--benchmark/webstreams/readable-async-iterator.js31
3 files changed, 116 insertions, 0 deletions
diff --git a/benchmark/webstreams/creation.js b/benchmark/webstreams/creation.js
new file mode 100644
index 0000000000..085faba8b8
--- /dev/null
+++ b/benchmark/webstreams/creation.js
@@ -0,0 +1,49 @@
+'use strict';
+const common = require('../common.js');
+const {
+ ReadableStream,
+ TransformStream,
+ WritableStream,
+} = require('node:stream/web');
+const assert = require('assert');
+
+const bench = common.createBenchmark(main, {
+ n: [50e3],
+ kind: ['ReadableStream', 'TransformStream', 'WritableStream']
+});
+
+let rs, ws, ts;
+
+function main({ n, kind }) {
+ switch (kind) {
+ case 'ReadableStream':
+ bench.start();
+ for (let i = 0; i < n; ++i)
+ rs = new ReadableStream();
+ bench.end(n);
+
+ // Avoid V8 deadcode (elimination)
+ assert.ok(rs);
+ break;
+ case 'WritableStream':
+ bench.start();
+ for (let i = 0; i < n; ++i)
+ ws = new WritableStream();
+ bench.end(n);
+
+ // Avoid V8 deadcode (elimination)
+ assert.ok(ws);
+ break;
+ case 'TransformStream':
+ bench.start();
+ for (let i = 0; i < n; ++i)
+ ts = new TransformStream();
+ bench.end(n);
+
+ // Avoid V8 deadcode (elimination)
+ assert.ok(ts);
+ break;
+ default:
+ throw new Error('Invalid kind');
+ }
+}
diff --git a/benchmark/webstreams/pipe-to.js b/benchmark/webstreams/pipe-to.js
new file mode 100644
index 0000000000..a41b31b5e1
--- /dev/null
+++ b/benchmark/webstreams/pipe-to.js
@@ -0,0 +1,36 @@
+'use strict';
+const common = require('../common.js');
+const {
+ ReadableStream,
+ WritableStream,
+} = require('node:stream/web');
+
+const bench = common.createBenchmark(main, {
+ n: [5e6],
+ highWaterMarkR: [512, 1024, 2048, 4096],
+ highWaterMarkW: [512, 1024, 2048, 4096],
+});
+
+
+async function main({ n, highWaterMarkR, highWaterMarkW }) {
+ const b = Buffer.alloc(1024);
+ let i = 0;
+ const rs = new ReadableStream({
+ highWaterMark: highWaterMarkR,
+ pull: function(controller) {
+ if (i++ === n) {
+ controller.enqueue(b);
+ } else {
+ controller.close();
+ }
+ }
+ });
+ const ws = new WritableStream({
+ highWaterMark: highWaterMarkW,
+ write(chunk, controller) {},
+ close() { bench.end(n); },
+ });
+
+ bench.start();
+ rs.pipeTo(ws);
+}
diff --git a/benchmark/webstreams/readable-async-iterator.js b/benchmark/webstreams/readable-async-iterator.js
new file mode 100644
index 0000000000..0d7e4737e3
--- /dev/null
+++ b/benchmark/webstreams/readable-async-iterator.js
@@ -0,0 +1,31 @@
+'use strict';
+const common = require('../common.js');
+const {
+ ReadableStream,
+} = require('node:stream/web');
+
+const bench = common.createBenchmark(main, {
+ n: [1e5],
+});
+
+
+async function main({ n }) {
+ const rs = new ReadableStream({
+ pull: function(controller) {
+ controller.enqueue(1);
+ }
+ });
+
+ let x = 0;
+
+ bench.start();
+ for await (const chunk of rs) {
+ x += chunk;
+ if (x > n) {
+ break;
+ }
+ }
+ // Use x to ensure V8 does not optimize away the loop as a noop.
+ console.assert(x);
+ bench.end(n);
+}