Ternary vs Switch vs If (v16)

Revision 16 of this benchmark created on


Description

Testing which is faster, ternary, switch, if, if else if, or if else if else.

Setup

var a;
    t1= function(){for (var i = 0; i < 10000000; i++) {
            a = i < 100 ? 1 : 2;
        }
    }
    t2= function() {for (var i = 0; i < 10000000; i++) {
            if(i < 100) {a = 1}else{a = 2}
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Terary
t1()
ready
Switch
t2()
ready

Revisions

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