Convert to number (v2)

Revision 2 of this benchmark created on


Description

The fastest way to convert string to number

Setup

function rndStr() {
	// concatenated string
	return String(Math.trunc(Math.random() * 1000000000000)) + '0';
}
// black hole to prevent dead code elimination
var bh = 0;

Teardown

if (Math.random() > 1) console.log(bh);

Test runner

Ready to run.

Testing in
TestOps/sec
+
bh += +rndStr();
ready
Number
bh += Number(rndStr());
ready
parseInt
bh += parseInt(rndStr());
ready
right shift
bh += rndStr() >> 0;
ready
parseFloat
bh += parseFloat(rndStr());
ready
parseInt 10
bh += parseInt(rndStr(), 10);
ready

Revisions

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