Created
December 7, 2017 15:47
-
-
Save evanslify/2d37b29f13fac964452dd1ea8c30649e 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 performance = require('perf_hooks').performance | |
const cluster = require('cluster'); | |
const http = require('http'); | |
const numCPUs = require('os').cpus().length; | |
if (cluster.isMaster) { | |
for (let i = 0; i < numCPUs; i++) { | |
cluster.fork() | |
} | |
} else { | |
performance.mark('start') | |
let s = 0 | |
for (var i = 0; i < 100000; ++i) { | |
s += Math.random() | |
} | |
performance.mark('end') | |
performance.measure('duration', 'start', 'end') | |
let measure = performance.getEntriesByName('duration')[0] | |
console.log(measure.duration) | |
cluster.worker.kill() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment