parseFloat .toFixed vs. Math.round (v8)

Revision 8 of this benchmark created on


Description

added straight toFixed() to show performance of parseFloat()

Setup

var test = [1.2345, 2.340000001, 3.00, 4.56789012, 67898888888888.1000001];
    var i = 0;
    var len = test.length;
    var n = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.round
for (i = 0; i < len; i++) {
  n = Math.round(test[i] * 1000000) / 1000000;
}
ready
parseFloat .toFixed
for (i = 0; i < len; i++) {
  n = parseFloat(test[i].toFixed(6));
}
ready

Revisions

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