加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
workers_startup_bench.ts 793 Bytes
一键复制 编辑 原始数据 按行查看 历史
// Benchmark measures time it takes to start and stop a number of workers.
const workerCount = 50;
async function bench(): Promise<void> {
const workers: Worker[] = [];
for (var i = 1; i <= workerCount; ++i) {
const worker = new Worker("./subdir/bench_worker.ts");
const promise = new Promise(
(resolve): void => {
worker.onmessage = (e): void => {
if (e.data.cmdId === 0) resolve();
};
}
);
worker.postMessage({ cmdId: 0, action: 2 });
await promise;
workers.push(worker);
}
console.log("Done creating workers closing workers!");
for (const worker of workers) {
worker.postMessage({ action: 3 });
await worker.closed; // Required to avoid a cmdId not in table error.
}
console.log("Finished!");
}
bench();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化