parse Str 2 Num: Number() vs parseInt() vs plus vs bitwise vs Math.* vs JSON (v66)

Revision 66 of this benchmark created on


Setup

function getRandomNumberString(){
    var response = "";
    for (var i = 0; i < Math.floor(Math.random() * 10); i++){
     response += Math.floor(Math.random() * i * 10);
    }
    return response;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Number Constructor
Number(getRandomNumberString());
ready
parseInt
parseInt(getRandomNumberString());
ready
Plus operator
+getRandomNumberString();
ready
Bitwise >> (right shift)
getRandomNumberString() >> 0;
ready
Multiply (force cast)
getRandomNumberString() * 1;
ready
Bitwise NOT
~~getRandomNumberString();
ready
parseInt with base argument
parseInt(getRandomNumberString(), 10);
ready
Bitwise OR
getRandomNumberString() | 0
ready
minus 0
getRandomNumberString() - 0;
ready
floor conversion
Math.floor(getRandomNumberString())
ready
round conversion
Math.round(getRandomNumberString())
ready
parseFloat
parseFloat(getRandomNumberString())
ready
parseFloat with base argument
parseFloat(getRandomNumberString(), 10)
ready
JSON.parse
JSON.parse(getRandomNumberString())
ready

Revisions

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