I\'m writing a library for WebWorkers, and I want to test the difference between running a script in the main page thread, versus in one or more workers. The problem is: I can\'
/**
* Block CPU for the given amount of seconds
* @param {Number} [seconds]
*/
function slowdown(seconds = 0.5) {
const start = (new Date()).getTime()
let end = start
while (end - start < seconds * 1000) {
end = (new Date()).getTime()
}
}
Calling this method will slow code down for the given amount of seconds (with ~200ms precision).