JavaScript bitwise NOT vs Math.floor() (v37)

Revision 37 of this benchmark created by fds on


Setup

var test = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor()
var test;
function isVerticalMovement(k){
      return ~[3, 4].indexOf(k);
    }
for (var i = 0; i < 1000000; i++) {
  test = isVerticalMovement(i);
}
ready
bitwise NOT
var test;
function isVerticalMovement(k){
      return [3, 4].indexOf(k) +1;
    }
for (var i = 0; i < 1000000; i++) {
  test = isVerticalMovement(i);
}
ready

Revisions

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