Created
June 22, 2018 05:39
-
-
Save deleteman/df2119b1d386d3de3f2d86bad12ff32e to your computer and use it in GitHub Desktop.
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
const { parentPort } = require('worker_threads'); | |
function random(min, max) { | |
return Math.random() * (max - min) + min | |
} | |
const sorter = require("./test2-worker"); | |
const start = Date.now() | |
let bigList = Array(1000000).fill().map( (_) => random(1,10000)) | |
/** | |
//you can receive messages from the main thread this way: | |
parentPort.on('message', (msg) => { | |
console.log("Main thread finished on: ", (msg.timeDiff / 1000), " seconds..."); | |
}) | |
*/ | |
sorter.sort(bigList); | |
parentPort.postMessage({ val: sorter.firstValue, timeDiff: Date.now() - start}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment