Number() vs parseInt() vs plus vs bitwise (v32)

Revision 32 of this benchmark created by Petr Nevyhoštěný on


Setup

var x = String(Math.random()*10000);

Test runner

Ready to run.

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

Revisions

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