Skip to content

Instantly share code, notes, and snippets.

@noscripter
Forked from sorenlouv/cpu-intensive.js
Created September 28, 2021 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noscripter/3db3900f11eb42f746210041aac00fe4 to your computer and use it in GitHub Desktop.
Save noscripter/3db3900f11eb42f746210041aac00fe4 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, 7); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i);
};
console.timeEnd('mySlowFunction');
}
mySlowFunction(8); // higher number => more iterations => slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment