Script Preparation code:
x
 
var a = 10;
var b = 2;
var c = 0;
var curObj = {
  a : a,
  b : b,
  c : c
};
var nonZeroDivisorResult = 0;
var zeroDivisorResult = 0;
Tests:
  • IF Logic

     
    if(b){
      nonZeroDivisorResult = a/b;
    }
    else{
      nonZeroDivisorResult = 0;
    }
    if(c){
      zeroDivisorResult = a/c;
    }
    else{
      zeroDivisorResult = 0;
    }
  • Ternary Logic

     
    nonZeroDivisorResult = b ? a/b : 0;
    zeroDivisorResult = c ? a/c : 0;
  • AND Logic

     
    nonZeroDivisorResult = b && a/b;
    zeroDivisorResult = c && a/c;
  • IF Logic with sloppy variable handling

     
    if(curObj.b){
      nonZeroDivisorResult = curObj.a/curObj.b;
    }
    else{
      nonZeroDivisorResult = 0;
    }
    if(curObj.c){
      zeroDivisorResult = curObj.a/curObj.c;
    }
    else{
      zeroDivisorResult = 0;
    }
  • Ternary Logic with sloppy variable handling

     
    nonZeroDivisorResult = curObj.b ? curObj.a/curObj.b : 0;
    zeroDivisorResult = curObj.c ? curObj.a/curObj.c : 0;
  • AND Logic with sloppy variable handling

     
    nonZeroDivisorResult = curObj.b && curObj.a/curObj.b;
    zeroDivisorResult = curObj.c && curObj.a/curObj.c;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    IF Logic
    Ternary Logic
    AND Logic
    IF Logic with sloppy variable handling
    Ternary Logic with sloppy variable handling
    AND Logic with sloppy variable handling

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Chrome 110 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
IF Logic 2141673.0 Ops/sec
Ternary Logic 2119026.5 Ops/sec
AND Logic 2221237.5 Ops/sec
IF Logic with sloppy variable handling 2201980.2 Ops/sec
Ternary Logic with sloppy variable handling 2019572.9 Ops/sec
AND Logic with sloppy variable handling 2223946.8 Ops/sec