parseFloat .toFixed vs. Math.round (v7)

Revision 7 of this benchmark created by Arvind on


Description

Adding support for whole numbers, by manually padding "00" when using math.round

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
var test = [1.2345, 2.3456, 3.4567, 4.5678, 5.6789, 67];

for (var i = 0; i < test.length; i++) {
  var number = Math.round(test[i] * 100) / 100 + "";
  var ar = number.split(".");
  var str = ar[0] + "." + (ar[1] || "00");

}
ready
parseFloat .toFixed
var test = [1.2345, 2.3456, 3.4567, 4.5678, 5.6789, 67];

for (var i = 0; i < test.length; i++) {
  (test[i].toFixed(2));
}
ready

Revisions

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