Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15
Safari 14
Mac OS X 10.15.6
Desktop
4 years ago
Test name Executions per second
floor 2219855.5 Ops/sec
~~ 3629946.2 Ops/sec
>> 0 3777902.2 Ops/sec
| 0 3812087.8 Ops/sec
<< 0 3835182.8 Ops/sec
& 0xFFFFFFFFFFFF 3895158.2 Ops/sec
^ 0x000000000000 3874015.0 Ops/sec
Math.trunc() 2289812.0 Ops/sec
x - (x % 1) 2457797.2 Ops/sec
parseInt() 2035740.9 Ops/sec
Script Preparation code:
AخA
 
var x = Math.random() * 100000000;
var y;
Tests:
  • floor

     
    y = Math.floor(x);
  • ~~

     
    y = ~~x;
  • >> 0

     
    y = x >> 0;
  • | 0

     
    y = x | 0;
  • << 0

     
    y = x << 0;
  • & 0xFFFFFFFFFFFF

     
    y = x & 0xFFFFFFFFFFFF;
  • ^ 0x000000000000

     
    y = x ^ 0x000000000000;
  • Math.trunc()

     
    y = Math.trunc(x);
  • x - (x % 1)

     
    y = x - (x % 1);
  • parseInt()

     
    y = parseInt(x)