GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: use the ring buffer for pending BYOB pull-into descriptors · nodejs/node@cfad2ef

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/webstreams
    • tee.js
  • lib/internal/webstreams
    • readablestream.js
  • test/parallel
    • test-whatwg-readablestream.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/webstreams/tee.js‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { ReadableStream } = require('node:stream/web');
4+
5+
const bench = common.createBenchmark(main, {
6+
n: [1e5],
7+
type: ['normal', 'bytes'],
8+
});
9+
10+
async function main({ n, type }) {
11+
let i = 0;
12+
const source = type === 'bytes' ?
13+
{
14+
type: 'bytes',
15+
pull(controller) {
16+
if (i++ < n) controller.enqueue(new Uint8Array(16));
17+
else controller.close();
18+
},
19+
} :
20+
{
21+
pull(controller) {
22+
if (i++ < n) controller.enqueue('a');
23+
else controller.close();
24+
},
25+
};
26+
27+
const rs = new ReadableStream(source);
28+
const [branch1, branch2] = rs.tee();
29+
const reader1 = branch1.getReader();
30+
const reader2 = branch2.getReader();
31+
let reads = 0;
32+
33+
bench.start();
34+
for (;;) {
35+
const [result1, result2] = await Promise.all([
36+
reader1.read(),
37+
reader2.read(),
38+
]);
39+
if (result1.done || result2.done) break;
40+
reads++;
41+
}
42+
bench.end(reads);
43+
console.assert(reads === n);
44+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.