Bitwise vs bitwise vs Math.trunc vs Math.trunc polyfill

Benchmark created by J on


Setup

var x = -3.999;
  var y = 3.999;
  var z = 125.11111;
  
  var mathTrunc = function( val ) {
      return val < 0 ? Math.ceil(val) : Math.floor(val);
  };

Test runner

Ready to run.

Testing in
TestOps/sec
Bitwise
x | 0;
y | 0;
z | 0;
ready
Bitwise >>
x >> 0;
y >> 0;
z >> 0;
ready
Math.trunc
Math.trunc(x);
Math.trunc(y);
Math.trunc(z);
ready
Math.trunc polyfill
mathTrunc(x);
mathTrunc(y);
mathTrunc(z);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.