Skip to content

Instantly share code, notes, and snippets.

@chnbohwr
Created June 25, 2018 08:57
Show Gist options
  • Save chnbohwr/807825f7cf1aa43e2bd591c78c4a41fc to your computer and use it in GitHub Desktop.
Save chnbohwr/807825f7cf1aa43e2bd591c78c4a41fc to your computer and use it in GitHub Desktop.
const { Worker } = require('worker_threads');
const path = require('path');
const arrayCount = 2000000;
const threadCount = 4;
let initialTime = new Date();
for (let i = 0; i < threadCount; i++) {
const worker = new Worker(path.resolve('./worker.js'));
worker.on('message', () => {
const now = new Date();
console.log(`[worker ${worker.threadId} finish]: ${now - initialTime} ms`);
});
worker.postMessage(arrayCount / threadCount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment