Tests:
  • bitLen using while loop

    x
     
    function bitLength(number) {
      let bitsCounter = 0;
      while ((1 << bitsCounter) <= number) {
        bitsCounter += 1;
      }
      return bitsCounter;
    }
  • bitLen using Number

     
    function bitLength(number) {
      return Number(number).toString(2).length;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    bitLen using while loop
    bitLen using Number

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Chrome 79 on Linux
View result in a separate tab
Test name Executions per second
bitLen using while loop 735132736.0 Ops/sec
bitLen using Number 736665728.0 Ops/sec