Math.pow vs Bitwise

JavaScript performance comparison

Revision 2 of this test case created by gdz

Preparation code

  var a = 4,
      b = 2,
      c = 0,
      Pow = Math.pow;

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
c = Pow(a, b);
c = a << b;

Compare results of other browsers


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.

Comment form temporarily disabled.

Add a comment