diff --git a/benchmarks/websocket-benchmark.mjs b/benchmarks/websocket-benchmark.mjs index e9af6646697..a16233c8e76 100644 --- a/benchmarks/websocket-benchmark.mjs +++ b/benchmarks/websocket-benchmark.mjs @@ -79,11 +79,11 @@ experiments['undici'] = { if (typeof WebSocketStream === 'function') { experiments['undici - stream'] = { fn: (ws, binary) => { - const { readable, writable } = ws /** @type {ReadableStreamDefaultReader} */ - const reader = readable.getReader() + const reader = ws.reader /** @type {WritableStreamDefaultWriter} */ - const writer = writable.getWriter() + const writer = ws.writer + return async (ev) => { ev.start() await writer.write(binary) @@ -95,7 +95,11 @@ if (typeof WebSocketStream === 'function') { connect: async (url) => { const ws = new WebSocketStream(url) - return await ws.opened + const { readable, writable } = await ws.opened + const reader = readable.getReader() + const writer = writable.getWriter() + + return { reader, writer, close: () => ws.close() } }, binaries @@ -158,12 +162,16 @@ async function init () { const ws = await connect('ws://localhost:5001') + const needShowBytes = binaries.length !== 2 || typeof binaries[0] === typeof binaries[1] for (let i = 0; i < binaries.length; ++i) { const binary = binaries[i] const bytes = Buffer.byteLength(binary) const binaryType = typeof binary === 'string' ? 'string' : 'binary' - const roundName = `${name} [${Math.floor(bytes / (1024))}Kib (${binaryType})]` + const roundName = needShowBytes + ? `${name} [${Math.floor(bytes / 1024)}Kib (${binaryType})]` + : `${name} [${binaryType}]` + round[roundName] = fn(ws, binary) experimentsInfo[roundName] = { bytes, binaryType } }