Skip to content

Commit

Permalink
fix: bench/stream-readable.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Jun 23, 2024
1 parent 93aedcf commit 56cd783
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions bench/stream-readable.mjs
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()

0 comments on commit 56cd783

Please sign in to comment.