Math.pow vs Bitwise

JavaScript performance comparison

Revision 2 of this test case created by gdz

Preparation code

<script>
  var a = 4,
      b = 2,
      c = 0,
      Pow = Math.pow;
</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
Math.pow
c = Pow(a, b);
pending…
Bitwise
c = a << b;
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:

1 comment

witek commented :

This codes aren't equivalent at all. If you know that a=4, and b=2, then just write c=16. For this particular case 4^2 == 4<<2, but in general it is not true. 16^2==256, 16<<2 == 64, for example.

Add a comment