ternary operator vs. if statement (v11)

Revision 11 of this benchmark created on


Setup

var x,
    count1 = 150,
    count2 = 75;

Test runner

Ready to run.

Testing in
TestOps/sec
ternary operator (false case)
if (count1 > 100) {
  x = Math.ceil(count1 / 4);
} else {
  x = count1;
}
ready
if statement (false case)
if (count2 > 100) {
  x = Math.ceil(count2 / 4);
} else {
  x = count2;
}
ready
if statement (true case)
x = count2 > 100 ? Math.ceil(count2 / 4) : count2; // false
ready
ternary operator (true case)
x = count1 > 100 ? Math.ceil(count1 / 4) : count1; // true
ready

Revisions

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