ternary vs else if

Benchmark created by vamsi on


Test runner

Ready to run.

Testing in
TestOps/sec
else if
var x = 1,
    y;
if (x == 1) y = 10
else if (x == 3) y = 30
else if (x == 4) y = 40
else y = 19
ready
ternary
var x = 1,
    y;
y = (x == 1) ? 10 : (x == 3) ? 30 : (x == 4) ? 40 : 19
ready

Revisions

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