sqrt perf

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function sqrt(num) {
      // Create an initial guess by simply dividing by 3.
      var lastGuess, guess = num / 3;
     
      // Loop until a good enough approximation is found.
      do {
        lastGuess = guess;  // store the previous guess
     
        // find a new guess by averaging the old one with
        // the original number divided by the old guess.
        guess = (num / guess + guess) / 2;
     
      // Loop again if the product isn't close enough to
      // the original number.
      } while(Math.abs(lastGuess - guess) > 5e-15);
     
      return guess;  // return the approximate square root
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native
Math.sqrt(1)
pending…
sqrt fn
sqrt(1)
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment