Skip to content

passing worker as blob - #2

Open
shevernitskiy wants to merge 2 commits into
denosaurs:masterfrom
shevernitskiy:bloby-thing
Open

passing worker as blob#2
shevernitskiy wants to merge 2 commits into
denosaurs:masterfrom
shevernitskiy:bloby-thing

Conversation

@shevernitskiy

Copy link
Copy Markdown

Closes #1

So it works... at least for an example from readme :D
But test fails. I think that is because ts compiler warnings.

import { parry } from "./mod.ts";

async function countSerial(limit: number): Promise<void> {
  for (let i = 0; i < limit; i++) {}
}

console.time("4x CountSerial");
await Promise.all([
  countSerial(1e9),
  countSerial(1e9),
  countSerial(1e9),
  countSerial(1e9),
]);
console.timeEnd("4x CountSerial");

const threads = [
  parry(countSerial),
  parry(countSerial),
  parry(countSerial),
  parry(countSerial),
];

console.time("4x CountParallel");
await Promise.all([
  threads[0](1e9),
  threads[1](1e9),
  threads[2](1e9),
  threads[3](1e9),
]);
console.timeEnd("4x CountParallel");

parry.close();

Gives as expected:

4x CountSerial: 2303ms
4x CountParallel: 658ms

@shevernitskiy
shevernitskiy marked this pull request as ready for review March 27, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

suggestion pass worker code as blob

1 participant