Simple Ternary vs Swtich vs If...Else (v5)

Revision 5 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Ternary
var a = 11;
var numberLiteral = a == 5 ? 'Five' : 'Other Number';
ready
If...Else
var a = 11,
    numberLiteral;

if (a == 5) {
 numberLiteral = 'Five';
} else {
 numberLiteral = 'Other Number';
}
ready
Switch
var a = 11,
    numberLiteral;

switch (a) {
case 5:
 numberLiteral = 'Five';
 break;
default:
 numberLiteral = 'Other Number';
}
ready

Revisions

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