Pow2

JavaScript performance comparison

Test case created by @thurmda

Preparation code

<script>
  var high = Math.pow(2,50);
  var rx = /^10*$/;
  function isPow2rx(x){return (rx.test(x.toString(2)));}
  function isPow2bi(x){return !(x&x-1) && x>0}
</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
RegEx
for(var i = 0; i < 9999; i++){
        isPow2rx(i);
}
pending…
Bin
for(var i = 0; i < 9999; i++){
        isPow2bi(i);
}
pending…
RegEx-High
for(var i = high - 10000; i <= high; i++){
        isPow2rx(i);
}
pending…
Bin-High
for(var i = high - 10000; i <= high; i++){
        isPow2bi(i);
}
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