Number() vs parseInt() vs plus vs bitwise

JavaScript performance comparison

Revision 33 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var x = String(Math.random()*10000);

};
</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
Math.floor
Math.floor(x)
pending…
parseFloat
parseFloat(x, 10)
pending…
JSON.parse()
JSON.parse(x)
pending…
minus 0
x - 0;
pending…
Bitwise OR
x | 0
pending…
Bitwise NOT
~~x;
pending…
parseInt with base argument
parseInt(x, 10);
pending…
Multiply (force cast)
x * 1;
pending…
Bitwise >> (right shift)
x >> 0;
pending…
parseInt
parseInt(x);
pending…
Plus operator
+x;
pending…
Number Constructor
Number(x);
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