parseFloat .toFixed vs. Math.round (v12)

Revision 12 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
var test = [1.2345, 2.3456, 3.4567, 4.5678, 5.6789];
var round = 3;
for (var i = 0; i < test.length; i++) {
  var t = Math.pow(10, round);
  Math.round(test[i] * t) / t
}
ready
parseFloat .toFixed
var test = [1.2345, 2.3456, 3.4567, 4.5678, 5.6789];
var round = 3;
for (var i = 0; i < test.length; i++) {
  parseFloat(test[i].toFixed(round));
}
ready
Fixed+
var test = [1.2345, 2.3456, 3.4567, 4.5678, 5.6789];
var round = 3;
for (var i = 0; i < test.length; i++) {
  +test[i].toFixed(round);
}
ready

Revisions

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