Pow2

Benchmark created by @thurmda on


Preparation HTML

<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

Ready to run.

Testing in
TestOps/sec
RegEx
for(var i = 0; i < 9999; i++){
        isPow2rx(i);
}
ready
Bin
for(var i = 0; i < 9999; i++){
        isPow2bi(i);
}
ready
RegEx-High
for(var i = high - 10000; i <= high; i++){
        isPow2rx(i);
}
ready
Bin-High
for(var i = high - 10000; i <= high; i++){
        isPow2bi(i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.