Math.floor, parseInt, left shift and binary OR

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code


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

};

Benchmark.prototype.teardown = function() {
  delete i;

};
</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(i);
pending…
parseInt()
parseInt(i);
pending…
left shift
i << 0;
pending…
binary OR
0|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.

1 Comment

Arnor commented :

Oh right. Binary or. I would actually have expected the left shift to be faster since it's a no-op, but obviously or-ing 0 also is. Would be interesting to see in other browsers as well.