Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 Safari/604.1
Mobile Safari 14
iOS 14.5
Mobile
3 years ago
Test name Executions per second
floor 3843902.0 Ops/sec
~~ 6460320.5 Ops/sec
>> 0 6473022.0 Ops/sec
| 0 6513680.0 Ops/sec
<< 0 6470605.0 Ops/sec
& 0xFFFFFFFFFFFF 5573793.5 Ops/sec
^ 0x000000000000 4955018.5 Ops/sec
Math.trunc() 2604804.2 Ops/sec
x - (x % 1) 3112664.2 Ops/sec
parseInt() 1928593.6 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)