Math.floor vs Math.round vs parseInt vs Bitwise (v161)

Revision 161 of this benchmark created by Riccardo Bartoli on


Description

Rounding in all form possible

Setup

var floor = Math.floor;
    var round = Math.round;
    var parse_Int = parseInt;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
Math.floor(89.938 / 293.3);
Math.floor(83784 / 9289.2);
Math.floor(7 / 60);
ready
Math.round
Math.round(89.938 / 293.3);
Math.round(83784 / 9289.2);
Math.round(7 / 60);
ready
parseInt
parseInt(89.938 / 293.3);
parseInt(83784 / 9289.2);
parseInt(7 / 60);
ready
Bitwise |
89.938 / 293.3 | 0;
83784 / 9289.2 | 0;
7 / 60 | 0;
ready
Bitwise >>
89.938 / 293.3 >> 0;
83784 / 9289.2 >> 0;
7 / 60 >> 0;
ready
Bitwise ~~
~~(89.938 / 293.3);
~~(83784 / 9289.2);
~~(7 / 60);
ready
Bitwise <<
89.938 / 293.3 << 0;
83784 / 9289.2 << 0;
7 / 60 << 0;
ready
Cached Math.floor
floor(89.938 / 293.3);
floor(83784 / 9289.2);
floor(7 / 60);
ready
Cached Math.round
round(89.938 / 293.3);
round(83784 / 9289.2);
round(7 / 60);
ready
Cached parseInt
parse_Int(89.938 / 293.3);
parse_Int(83784 / 9289.2);
parse_Int(7 / 60);
ready
Hack with bitwise shift
(0.5 + 89.938 / 293.3) << 0;
(0.5 + 83784 / 9289.2) << 0;
(0.5 + 7 / 60) << 0;
ready
toFixed
(89.938 / 293.3).toFixed(0);
(83784 / 9289.2).toFixed(0);
(7 / 60).toFixed(0);
ready
Hack rounding
~~ (0.5 + 89.938 / 293.3);
~~ (0.5 + 83784 / 9289.2);
~~ (0.5 + 7 / 60);
ready
Hack Bitwise |
(0.5 + 89.938 / 293.3) | 0;
(0.5 + 83784 / 9289.2) | 0;
(0.5 + 7 / 60) | 0;
ready

Revisions

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