Using code profiling, I found that the Math.sqrt function is the main bottleneck in a large binary-nested loop that runs every timestep in my program. Is there any way to improve its performance? Should I embed some kind of iterative calculation or calculate a table based on a table?
Any help would be greatly appreciated!
Instead, I cannot replace it with quadratic calculation, since this is not a comparison.
EDIT: The corresponding piece of code looks something like this
var width = 2000;
var height = 2000;
function update() {
for (var j = 0; j < height; ++j) {
for (var i = 0; i < width; ++i) {
array[i][j] = Math.sqrt();
}
}
}
var fps = 60;
setInterval(update, 1000 / fps);
source
share