Skip to content

Instantly share code, notes, and snippets.

@spamshaker
Created October 23, 2023 14:24
Show Gist options
  • Save spamshaker/5f3dface13f3caf3fb67a13b68351ee5 to your computer and use it in GitHub Desktop.
Save spamshaker/5f3dface13f3caf3fb67a13b68351ee5 to your computer and use it in GitHub Desktop.
performance stress test
'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