Skip to content

Instantly share code, notes, and snippets.

@IshanArya
Forked from sorenlouv/cpu-intensive.js
Last active June 1, 2020 22:49
Show Gist options
  • Save IshanArya/55743f73a0892f19373986ff1dff951c to your computer and use it in GitHub Desktop.
Save IshanArya/55743f73a0892f19373986ff1dff951c to your computer and use it in GitHub Desktop.
A CPU intensive operation. Use to test imitate blocking code, test WebWorkers etc.
function mySlowFunction(baseNumber) {
console.time('mySlowFunction');
let result = 0;
for (var i = Math.pow(baseNumber, 10); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i);
};
console.timeEnd('mySlowFunction');
return result;
}
mySlowFunction(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment