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

Revision 53 of this benchmark created on


Description

Rounding in all form possible

Setup

var a = Math.random() * 1000;
    var b = Math.random() * 1000000;
    var c = Math.random() * 1000000000;
    var d = Math.random() * 10;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
 Math.floor(a / d);
Math.floor(b / a);
Math.floor(c / b);
ready
Math.round
Math.round(a / d); Math.round(b / a);
Math.round(c / b);
ready
parseInt
 parseInt(a / d);
 parseInt(b / a);
 parseInt(c / b);
ready
Bitwise |
(a / d) | 0;
(b / a) | 0;
 (c / b) | 0;
ready
Bitwise
 (a / d) >> 0;
 (b / a) >> 0;
 (c / b) >> 0;
ready
Bit flipping
 ~~(a / d);
 ~~(b / a);
 ~~(c / b);
ready
zero-fill right shift
(a / d) >>> 0;
(b / a) >>> 0;
(c / b) >>> 0;
ready

Revisions

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