Conditional return

Benchmark created by Akim McMath on


Setup

function ifStatement(a, b) {
    if (a && b) {
      return 1;
    } else {
      return 2;
    }
  }
  
  function ternaryOp(a, b) {
    return a && b ? 1 : 2;
  }
  
  function logicalOp(a, b) {
    return a && b && 1 || 2;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Conditional statement
ifStatement(true, true);
ifStatement(true, false);
ifStatement(false, true);
ifStatement(false, false);
ready
Ternary operator
ternaryOp(true, true);
ternaryOp(true, false);
ternaryOp(false, true);
ternaryOp(false, false);
ready
Logical operators
logicalOp(true, true);
logicalOp(true, false);
logicalOp(false, true);
logicalOp(false, false);
ready

Revisions

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

  • Revision 1: published by Akim McMath on