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 — benchmark: add a benchmark for read() of ReadableStreams · nodejs/node@4879e3f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/webstreams
    • readable-read.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/webstreams/readable-read.js‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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', 'byob'],
8+
});
9+
10+
async function main({ n, type }) {
11+
switch (type) {
12+
case 'normal': {
13+
const rs = new ReadableStream({
14+
pull: function(controller) {
15+
controller.enqueue('a');
16+
},
17+
});
18+
const reader = rs.getReader();
19+
let x = null;
20+
bench.start();
21+
for (let i = 0; i < n; i++) {
22+
const { value } = await reader.read();
23+
x = value;
24+
}
25+
bench.end(n);
26+
console.assert(x);
27+
break;
28+
}
29+
case 'byob': {
30+
const encode = new TextEncoder();
31+
const rs = new ReadableStream({
32+
type: 'bytes',
33+
pull: function(controller) {
34+
controller.enqueue(encode.encode('a'));
35+
},
36+
});
37+
const reader = rs.getReader({ mode: 'byob' });
38+
let x = null;
39+
bench.start();
40+
for (let i = 0; i < n; i++) {
41+
const { value } = await reader.read(new Uint8Array(1));
42+
x = value;
43+
}
44+
bench.end(n);
45+
console.assert(x);
46+
break;
47+
}
48+
}
49+
}

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.