Math.pow vs. simple multiplication

JavaScript performance comparison

Revision 4 of this test case created by SourceR

Preparation code

<p>
  Hi there, this is math, only. No Output here
</p>
<script type="application/javascript;version=1.8">
  // JavaScript 1.8 is currently available only in Firefox
  function square18(x) x * x;
</script>
<script>
  var x1 = Math.random();

  function ownSquare(num) {
    return num * num;
  }
// fallback
if(!square18) var square18 = ownSquare;
</script>
    

Preparation code output

<p> Hi there, this is math, only. No Output here </p> <script> var x1 = Math.random(); function ownSquare(num) { return num * num; } // fallback if(!square18) var square18 = ownSquare; </script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Simple Multiplication
e = x1 * x1;
pending…
Math.pow
e = Math.pow(x1, 2);
pending…
own Pow
e = ownSquare(x1);
pending…
Square from JS 1.8
e = square18(x1);
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.

0 Comments

Hi there, this is math, only. No Output here