Math.floor vs Math.round vs parseInt vs Bitwise vs Manual Round

JavaScript performance comparison

Revision 117 of this test case created by Shane Brinkman-Davis

Info

Rounding in all form possible

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(Math.random());
pending…
Math.round
Math.round(Math.random());
pending…
parseInt
parseInt(Math.random());
pending…
Bitwise |
Math.random() | 0;
pending…
Bitwise >>
Math.random() >> 0;
pending…
Bitwise ~~
~~
Math.random();
pending…
Bitwise <<
Math.random() << 0;
pending…
Manual Round
Math.random() + .5 | 0;
pending…
Math.ceil
Math.ceil(Math.random());
pending…
-~ (ceil equivalent)
-~Math.random();
pending…
control
Math.random()
pending…
control (string)
Math.random() + ""
pending…
parseInt string
parseInt(Math.random() + "")
pending…
string | 0
(Math.random() + "") | 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