Number() vs parseInt() vs plus vs bitwise (v98)

Revision 98 of this benchmark created on


Setup

var answer = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
  var str = '' + answer;
  var num;

Teardown



            console.assert(num === answer);
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
Number Constructor
num = Number(str);
ready
parseInt
num = parseInt(str);
ready
Plus operator
num = +str;
ready
Bitwise >> (right shift)
num = str >> 0;
ready
Multiply (force cast)
num = str * 1;
ready
Bitwise NOT
num = ~~str;
ready
parseInt with base argument
num = parseInt(str, 10);
ready
Bitwise OR
num = str | 0;
ready
minus 0
num = str - 0;
ready

Revisions

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