Script Preparation code:
x
 
var truthyBool = true;
var falsyBool = false;
//Currently set to -1, but will change to 1 (truthyNum) and 0 (falsyNum).
var truthyNum = -1;
var falsyNum = -1;
Tests:
  • If statement

     
    if(truthyBool === true){
      truthyNum = 1;
    }
    else{
      truthyNum = 0;
    }
    if(falsyBool === true){
      falsyNum = 1;
    }
    else{
      falsyNum = 0;
    }
  • Ternary

     
    truthyNum = truthyBool ? 1 : 0;
    falsyNum = falsyBool ? 1 : 0;
  • Unary

     
    truthyNum = +truthyBool;
    falsyNum = +falsyBool;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    If statement
    Ternary
    Unary

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 years ago)
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
IE 11 on Windows
View result in a separate tab
Test name Executions per second
If statement 103361800.0 Ops/sec
Ternary 86083152.0 Ops/sec
Unary 24825676.0 Ops/sec