integer exponentiation

JavaScript performance comparison

Revision 2 of this test case created and last updated

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    number = 1;
   
    function pow(n, x){
      var res=1, i;
      for(i = 0; i < x; i++){
        res *= n;
      }
      return res;
    }
   
    function pow_squaring(n, x){
      var r = 1;
      while(x > 1){
        if(x % 2 === 0) { n*=n; x/=2; }
        else { r*=n; x--; }
      }
      return n*r;
    }
};

Benchmark.prototype.teardown = function() {
    number = 1;
};
</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
multiplication
for(e=0; e < 10000; e++)
    pow(number++, e);
pending…
squaring
for(e=0; e < 10000; e++)
    pow_squaring(number++, e)
pending…
built-in (Math.pow)
for(e=0; e < 10000; e++)
    Math.pow(number++, e)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment