parseInt VS parseFloat (v11)

Revision 11 of this benchmark created on


Description

Exactly what the name says. Finally, the gloves are off.

VERDICT!

Chrome likes parseFloat more, unless you're trying to actually grab the integer value out of a floating-point string.

Firefox is just the opposite! What a country!

Setup

var str = "123px";
    var str2 = "123.123px";

Test runner

Ready to run.

Testing in
TestOps/sec
parseInt (Integer)
parseInt(str);
ready
parseInt (Integer, 10)
parseInt(str, 10);
ready
parseInt (Float)
parseInt(str2)
ready
parseInt (Float, 10)
parseInt(str2, 10)
ready
parseFloat (Integer)
parseFloat(str);
ready
parseFloat (Integer, 10)
parseFloat(str, 10);
ready
parseFloat (Float)
parseFloat(str2);
ready
parseFloat (Float, 10)
parseFloat(str2, 10);
ready
Plus Sign Int
+str.match(/\d+/)
ready
Plus sign Float
+str2.match(/\d+/)
ready
binary
~~str2.match(/\d+/)
ready
to numeric + binary
~~+str2.match(/\d+/)
ready
one more binary
str2.match(/\d+/)^0
ready

Revisions

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