Created
June 25, 2018 08:57
-
-
Save chnbohwr/807825f7cf1aa43e2bd591c78c4a41fc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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