| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f249614 commit 3b5bace
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,23 +6,40 @@ const { | |||
| 6 | 6 | ||
| 7 | 7 | const bench = common.createBenchmark(main, { | |
| 8 | 8 | n: [1e5], | |
| 9 | + type: ['normal', 'bytes'], | ||
| 9 | 10 | }); | |
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | - async function main({ n }) { | ||
| 13 | - const rs = new ReadableStream({ | ||
| 14 | - pull: function(controller) { | ||
| 15 | - controller.enqueue(1); | ||
| 16 | - }, | ||
| 17 | - }); | ||
| 13 | + async function main({ n, type }) { | ||
| 14 | + const rs = type === 'bytes' ? | ||
| 15 | + new ReadableStream({ | ||
| 16 | + type: 'bytes', | ||
| 17 | + pull: function(controller) { | ||
| 18 | + controller.enqueue(new Uint8Array(1)); | ||
| 19 | + }, | ||
| 20 | + }) : | ||
| 21 | + new ReadableStream({ | ||
| 22 | + pull: function(controller) { | ||
| 23 | + controller.enqueue(1); | ||
| 24 | + }, | ||
| 25 | + }); | ||
| 18 | 26 | ||
| 19 | 27 | let x = 0; | |
| 20 | 28 | ||
| 21 | 29 | bench.start(); | |
| 22 | - for await (const chunk of rs) { | ||
| 23 | - x += chunk; | ||
| 24 | - if (x > n) { | ||
| 25 | - break; | ||
| 30 | + if (type === 'bytes') { | ||
| 31 | + for await (const chunk of rs) { | ||
| 32 | + x += chunk.byteLength; | ||
| 33 | + if (x > n) { | ||
| 34 | + break; | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + } else { | ||
| 38 | + for await (const chunk of rs) { | ||
| 39 | + x += chunk; | ||
| 40 | + if (x > n) { | ||
| 41 | + break; | ||
| 42 | + } | ||
| 26 | 43 | } | |
| 27 | 44 | } | |
| 28 | 45 | // Use x to ensure V8 does not optimize away the loop as a noop. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments