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

Revision 122 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
mathRound
mathRound((89.938 / 293.3), 14);
mathRound((83784 / 9289.2, 14));
mathRound((7 / 60, 14));
ready
toPrecision
(89.938 / 293.3).toPrecision(14);
(83784 / 9289.2).toPrecision(14);
(7 / 60).toPrecision(14);
ready

Revisions

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