Math.floor vs Math.round vs parseInt vs Bitwise

JavaScript performance comparison

Revision 42 of this test case created by Marco Pfeiffer

Info

Rounding in all form possible

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = 89.938 / 293.3;
    var b = 83784 / 9289.2;
    var c = 7 / 60;
};
</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
Math.floor
Math.floor(a);
Math.floor(b);
Math.floor(c);
pending…
Math.round
Math.round(a);
Math.round(b);
Math.round(c);
pending…
parseInt
parseInt(a);
parseInt(b);
parseInt(c);
pending…
Bitwise |
a | 0;
b | 0;
c | 0;
pending…
Bitwise
a >> 0;
b >> 0;
c >> 0;
pending…
Bit flipping
~~a;
~~b;
~~c;
pending…
zero-fill right shift
a >>> 0;
b >>> 0;
c >>> 0;
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