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

Revision 121 of this benchmark created on


Description

Rounding in all form possible

Setup

var mathRound = function(val, exp) {
       if (exp) {
         return Math.round(val * Math.pow(10, exp)) / Math.pow(10, exp);
       } else {
         return Math.round(val);
       }
     };

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
Math.round(89.938 / 293.3);
Math.round(83784 / 9289.2);
Math.round(7 / 60);
ready
mathRound
mathRound(89.938 / 293.3);
mathRound(83784 / 9289.2);
mathRound(7 / 60);
ready
parseFloat
parseFloat(89.938 / 293.3);
parseFloat(83784 / 9289.2);
parseFloat(7 / 60);
ready
parseFloat - mathRound
parseFloat(mathRound(89.938 / 293.3));
parseFloat(mathRound(83784 / 9289.2));
parseFloat(mathRound(7 / 60));
ready
toPrecision
(89.938 / 293.3).toPrecision(14);
(83784 / 9289.2).toPrecision(14);
(7 / 60).toPrecision(14);
ready
mathRound
mathRound((89.938 / 293.3), 3);
mathRound((83784 / 9289.2, 3));
mathRound((7 / 60, 3));
ready

Revisions

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