Math.floor vs Math.round vs parseInt vs Bitwise

JavaScript performance comparison

Revision 122 of this test case created

Info

Rounding in all form possible

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
     var mathRound = function(val, exp) {
       if (exp) {
         return Math.round(val * Math.pow(10, exp)) / Math.pow(10, exp);
       } else {
         return Math.round(val);
       }
     };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
mathRound
mathRound((89.938 / 293.3), 14);
mathRound((83784 / 9289.2, 14));
mathRound((7 / 60, 14));
pending…
toPrecision
(89.938 / 293.3).toPrecision(14);
(83784 / 9289.2).toPrecision(14);
(7 / 60).toPrecision(14);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment