Get number of physical CPU cores in JavaScript?

Viewed 722

navigator.hardwareConcurrency returns the number of logical cores. In my experiments, the performance stops improving if I have more Web Workers than physical cores. Is there a way to get the number of physical cores?

1 Answers

I know it's an old question, but for anyone else passing by, you could use WebCPU.
It estimates the number of physical cores in the client:

import {WebCPU} from 'webcpu';

WebCPU.detectCPU().then(result => {
    console.log(`Reported Cores: ${result.reportedCores}`);
    console.log(`Estimated Idle Cores: ${result.estimatedIdleCores}`);
    console.log(`Estimated Physical Cores: ${result.estimatedPhysicalCores}`);
});
Related