JavaScript Math.sqrt performance
<p>Through code profiling, I have found the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt" rel="nofollow">Math.sqrt</a> function <em>specifically</em> to be a major bottleneck in a large doubly-nested loop that runs every timestep in my program. Is there any way to improve its performance? Should I inline some kind of iterative calculation, or lookup table-based calculation?</p>

<p>Any help would be greatly appreciated!</p>

<p>I cannot replace it with a squares calculation instead, since it is not a comparison.</p>

<p><strong>EDIT:</strong> The relevant portion of the code looks roughly as follows</p>

<pre><code>var width = 2000;
var height = 2000;

function update() {
    for (var j = 0; j &lt; height; ++j) {
        for (var i = 0; i &lt; width; ++i) {
            array[i][j] = Math.sqrt(/* some expression involving i and j */);
        }
    }
}

var fps = 60;
setInterval(update, 1000 / fps);
</code></pre>