-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,45 @@ | ||
import { skipIfVersion } from '../utils.mjs' | ||
import { Readable } from 'node:stream' | ||
import { ReadableStream } from 'node:stream/web' | ||
import assert from 'node:assert' | ||
import { createBenchmarkSuite } from '../common.mjs' | ||
|
||
skipIfVersion('<= 16.5.0') | ||
|
||
const suite = createBenchmarkSuite('Stream.Readable') | ||
|
||
suite | ||
.add('streams.Readable reading 1e3 * "some data"', { | ||
defer: true, | ||
fn: async function (deferred) { | ||
function* readImpl(_sizeT) { | ||
let i = 0 | ||
while (i < 1e3) { | ||
yield 'some data' | ||
++i | ||
} | ||
.add('streams.Readable reading 1e3 * "some data"', async () => { | ||
function* readImpl(_sizeT) { | ||
let i = 0 | ||
while (i < 1e3) { | ||
yield 'some data' | ||
++i | ||
} | ||
const readable = Readable.from(readImpl()) | ||
} | ||
const readable = Readable.from(readImpl()) | ||
|
||
try { | ||
for await (const _ of readable) { | ||
for await (const _ of readable) { | ||
assert.ok(_) | ||
} | ||
}, | ||
) | ||
.add('streams.web.Readable reading 1e3 * "some data"', async () => { | ||
let i = 0 | ||
const readable = new ReadableStream({ | ||
pull: function (controller) { | ||
controller.enqueue('some data') | ||
++i | ||
if (i >= 1e3) { | ||
controller.close() | ||
} | ||
deferred.resolve() | ||
} catch (e) { | ||
deferred.reject(e) | ||
} | ||
}, | ||
}) | ||
.add('streams.web.Readable reading 1e3 * "some data"', { | ||
defer: true, | ||
fn: async function (deferred) { | ||
let i = 0 | ||
const readable = new ReadableStream({ | ||
pull: function (controller) { | ||
controller.enqueue('some data') | ||
++i | ||
if (i >= 1e3) { | ||
controller.close() | ||
} | ||
}, | ||
}) | ||
}, | ||
}) | ||
|
||
try { | ||
for await (const _ of readable) { | ||
} | ||
deferred.resolve() | ||
} catch (e) { | ||
deferred.reject(e) | ||
} | ||
}, | ||
}) | ||
for await (const _ of readable) { | ||
assert.ok(_) | ||
} | ||
}, | ||
) | ||
|
||
await suite.runAndPrintResults() |