Tests:
  • LOGICAL approach

    AخA
     
    var result;
    for (let i = 0; i < 30000; i++) {
      const num = Math.floor(Math.random() * 1000);
      result = (num % 2 && 2) || 1;
    }
    return result;
  • TERNARY approach

     
    var result;
    for (let i = 0; i < 30000; i++) {
      const num = Math.floor(Math.random() * 1000);
      result = num % 2 ? 2 : 1;
    }
    return result;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    LOGICAL approach
    TERNARY approach

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 16 days ago)
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Chrome 126 on Chrome OS 14541.0.0
View result in a separate tab
Test name Executions per second
LOGICAL approach 948.9 Ops/sec
TERNARY approach 915.5 Ops/sec