Contagem de bits

JavaScript performance comparison

Revision 2 of this test case created by mgibsonbr

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function bitwise(x) {
      var bits = 1;
      while ( x >= (1 << bits) )
          bits++;
      return bits;
  }
  
  function aritmetica(x) {
      var bits = 1;
      var limite = 2;
      while ( x >= limite ) {
          bits++;
          limite *= 2;
      }
  }
  
  function logaritmo(numero) {
      return Math.floor( Math.log(numero) / Math.log(2) ) + 1;
  }

};
</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
Ciclo (bitwise)
for ( var i = 99900000 ; i < 100000000 ; i++ )
    var bits = bitwise(i);
pending…
Ciclo (aritmética)
for ( var i = 99900000 ; i < 100000000 ; i++ )
    var bits = aritmetica(i);
pending…
Logaritmo
for ( var i = 99900000 ; i < 100000000 ; i++ )
    var bits = logaritmo(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.

0 Comments