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

Revision 35 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 ~[KEY.UP, KEY.DOWN].indexOf(k);
    }
for (var i = 0; i < 100000; i++) {
  test = isVerticalMovement(i);
}
ready
bitwise NOT
var test;
function isVerticalMovement(k){
      return [KEY.UP, KEY.DOWN].indexOf(k) +1;
    }
for (var i = 0; i < 100000; i++) {
  test = isVerticalMovement(i);
}
ready

Revisions

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