-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #50107 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
- Loading branch information
Showing
4 changed files
with
163 additions
and
85 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const { MessageChannel } = require('worker_threads'); | ||
const { WritableStream, TransformStream, ReadableStream } = require('stream/web'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
payload: ['WritableStream', 'ReadableStream', 'TransformStream'], | ||
n: [1e4], | ||
}); | ||
|
||
function main({ n, payload: payloadType }) { | ||
let createPayload; | ||
let messages = 0; | ||
|
||
switch (payloadType) { | ||
case 'WritableStream': | ||
createPayload = () => new WritableStream(); | ||
break; | ||
case 'ReadableStream': | ||
createPayload = () => new ReadableStream(); | ||
break; | ||
case 'TransformStream': | ||
createPayload = () => new TransformStream(); | ||
break; | ||
default: | ||
throw new Error('Unsupported payload type'); | ||
} | ||
|
||
const { port1, port2 } = new MessageChannel(); | ||
|
||
port2.onmessage = onMessage; | ||
|
||
function onMessage() { | ||
if (messages++ === n) { | ||
bench.end(n); | ||
port1.close(); | ||
} else { | ||
send(); | ||
} | ||
} | ||
|
||
function send() { | ||
const stream = createPayload(); | ||
|
||
port1.postMessage(stream, [stream]); | ||
} | ||
|
||
bench.start(); | ||
send(); | ||
} |
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
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
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