bitwise operator vs. boolean logic when using TypedArrays

Bitwise operators are slow in javascript because there is implicit type conversion between floats and ints. If we use TypedArrays though, javascript engines shouldn't have to convert. But do they? This test is here to find out. We'll also check to see whether conversion is performed between another int-like datatypes, Uint32
4 months ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Test name Executions per second
bitwise operator on Int32Array 30403.3 Ops/sec
boolean operator on Int32Array 31158.9 Ops/sec
boolean operator with comparitors on Int32Array 29934.5 Ops/sec
bitwise operator on Float32Array 27976.6 Ops/sec
bitwise operator on Uint32Array 30078.2 Ops/sec
boolean operator on Uint32Array 31184.8 Ops/sec
boolean operator on Uint32Array with comparators 29773.5 Ops/sec
Script Preparation code:
Tests:
  • bitwise operator on Int32Array

  • boolean operator on Int32Array

  • boolean operator with comparitors on Int32Array

  • bitwise operator on Float32Array

  • bitwise operator on Uint32Array

  • boolean operator on Uint32Array

  • boolean operator on Uint32Array with comparators

Open this result on MeasureThat.net