| 45 | } |
| 46 | |
| 47 | function benchFromFirstBatch(chunks, chunkSize, n) { |
| 48 | const { from } = require('stream/iter'); |
| 49 | const chunk = new Uint8Array(chunkSize); |
| 50 | let seen = 0; |
| 51 | |
| 52 | (async () => { |
| 53 | bench.start(); |
| 54 | for (let i = 0; i < n; i++) { |
| 55 | const iterator = from(source(chunks, chunk))[Symbol.asyncIterator](); |
| 56 | const { value, done } = await iterator.next(); |
| 57 | if (done || value.length === 0) { |
| 58 | throw new Error('expected a batch'); |
| 59 | } |
| 60 | seen += value.length; |
| 61 | } |
| 62 | bench.end(n); |
| 63 | if (seen === 0) { |
| 64 | throw new Error('expected chunks'); |
| 65 | } |
| 66 | })(); |
| 67 | } |
| 68 | |
| 69 | function benchFromSyncWritev(chunks, chunkSize, n) { |
| 70 | const { pipeToSync } = require('stream/iter'); |