Math.floor vs Math.round vs parseInt vs Bitwise vs Manual Round (v117)

Revision 117 of this benchmark created by Shane Brinkman-Davis on


Description

Rounding in all form possible

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
Math.floor(Math.random());
ready
Math.round
Math.round(Math.random());
ready
parseInt
parseInt(Math.random());
ready
Bitwise |
Math.random() | 0;
ready
Bitwise >>
Math.random() >> 0;
ready
Bitwise ~~
~~
Math.random();
ready
Bitwise <<
Math.random() << 0;
ready
Manual Round
Math.random() + .5 | 0;
ready
Math.ceil
Math.ceil(Math.random());
ready
-~ (ceil equivalent)
-~Math.random();
ready
control
Math.random()
ready
control (string)
Math.random() + ""
ready
parseInt string
parseInt(Math.random() + "")
ready
string | 0
(Math.random() + "") | 0
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.