Skip to content

Instantly share code, notes, and snippets.

@evanslify
Created December 7, 2017 15:47
Show Gist options
  • Save evanslify/2d37b29f13fac964452dd1ea8c30649e to your computer and use it in GitHub Desktop.
Save evanslify/2d37b29f13fac964452dd1ea8c30649e to your computer and use it in GitHub Desktop.
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