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

Revision 13 of this 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;
    function num(e,i,o){
        var t = Number(e);
        if(!isNaN(t))
            result += t;
    }
    function pai(e,i,o){
        var t = parseInt(e);
        if(!isNaN(t))
            result += t;
    }
    function paf(e,i,o){
        var t = parseFloat(e);
        if(!isNaN(t))
            result += t;
    }
    function imp(e,i,o){
        var t = +e;
        if(!isNaN(t))
            result += t;
    }
    function bor(e,i,o){
        result += 0|e;
    }
    function bxo(e,i,o){
        result += 0^e;
    }
    function bno(e,i,o){
        result += ~~e;
    }
    function ble(e,i,o){
        result += e<<0;
    }
    function bri(e,i,o){
        result += e>>0;
    }
    function bbr(e,i,o){
        result += e>>>0;
    }

Teardown


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

Test runner

Ready to run.

Testing in
TestOps/sec
Number()
Benchmark.each(abc, num, window);
ready
parsetInt()
Benchmark.each(abc, pai, window);
ready
parseFloat()
Benchmark.each(abc, paf, window);
ready
implicit
Benchmark.each(abc, imp, window);
ready
Bitwse OR
Benchmark.each(abc, bor, window);
ready
Bitwise XOR
Benchmark.each(abc, bxo, window);
ready
Bitwise NOT NOT
Benchmark.each(abc, bno, window);
ready
Bitwise Left Shift
Benchmark.each(abc, ble, window);
ready
Bitwise Right Shift
Benchmark.each(abc, bri, window);
ready
Bitwise Bitwise Right Shift
Benchmark.each(abc, bbr, window);
ready

Revisions

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