Created
October 23, 2023 14:24
-
-
Save spamshaker/5f3dface13f3caf3fb67a13b68351ee5 to your computer and use it in GitHub Desktop.
performance stress test
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
'use strict'; | |
const cluster = require('cluster'); | |
const os = require('os'); | |
const now = () => performance.now(); | |
let time = 10000; | |
let start = now(); | |
let end = start + time; | |
if (cluster.isMaster) { | |
let total = 0; | |
const numCPUs = os.cpus().length; | |
// console.log('Creating', numCPUs, 'clusters'); | |
for (let i = 0; i < numCPUs; ++i) { | |
const forked = cluster.fork(); | |
forked.on('message', (count) => { | |
return total += count; | |
}); | |
} | |
process.on('exit', () => { | |
console.log( | |
'Number operations', total, | |
', Time(s):', time / 1000, | |
', Num clusters (CPUs)', numCPUs | |
// ', Details:', details | |
); | |
}); | |
} else if (cluster.isWorker) { | |
let count = 0; | |
while (now() <= end) { | |
count++; | |
} | |
process.send(count); | |
cluster.worker.disconnect(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment