Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15
Safari 14
Mac OS X 10.14.6
Desktop
3 years ago
Test name Executions per second
floor 3210191.8 Ops/sec
~~ 5618325.5 Ops/sec
>> 0 5636475.0 Ops/sec
| 0 5643876.0 Ops/sec
<< 0 5646532.0 Ops/sec
& 0xFFFFFFFFFFFF 5626098.5 Ops/sec
^ 0x000000000000 5589204.0 Ops/sec
Math.trunc() 3280309.5 Ops/sec
x - (x % 1) 3705066.0 Ops/sec
parseInt() 2924251.0 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)