best of string to number conversion, allowing default NaN or 0

Benchmark created by Including Bitwise Operators on


Setup

var abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], result = 0;

Teardown



            if(result % 90 !== 0)
      throw "Test not implemented properly; result = " + result;
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
Number()
var t;
for(var i in abc){
    t = Number(abc[i]);
    if(t)
        result += t;
}
ready
Bitwise Bitwise Right Shift
for(var i in abc){
    result += abc[i]>>>0;
}
ready
parseInt()
var t;
for(var i in abc){
    t = parseInt(abc[i]);
    if(t)
        result += t;
}
ready
Bitwise OR
for(var i in abc){
    result += 0|abc[i];
}
ready
Bitwise Left Shift
for(var i in abc){
    result += abc[i]<<0;
}
ready
parseFloat()
var t;
for(var i in abc){
    t = parseFloat(abc[i]);
    if(t)
        result += t;
}
ready
Bitwise XOR
for(var i in abc){
    result += 0^abc[i];
}
ready
Bitwise NOT NOT
for(var i in abc){
    result += ~~abc[i];
}
ready
implicit
var t;
for(var i in abc){
    t = +abc[i];
    if(t)
        result += t;
}
ready
Bitwise Right Shift
for(var i in abc){
    result += abc[i]>>0;
}
ready

Revisions

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

  • Revision 1: published by Including Bitwise Operators on