powerRecursive

JavaScript performance comparison

Test case created by Robert Green

Info

Test recursive power function versus iterative

Preparation code

<script>
  function power(base, exponent) {
    return exponent == 0? 1 : base * power(base, exponent - 1);
  }
 
  function powerNR(base, exp) {
    var result = 1;
    while(exp--) {
      result *= base;
    }
    return result;
  }
  var x = 5, y = 11;
</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
Recursive
power(x, y)
pending…
Iterative
powerNR(x, y)
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