modulo vs bitwise (v11)

Revision 11 of this benchmark created on


Setup

var arr = [];
    var i = 1E4;
    
    while (i--) {
        arr.push(Math.round(Math.random()*1E4));
    }

Test runner

Ready to run.

Testing in
TestOps/sec
modulo
var j = arr.length;
var x;
while (j--) {
 if (x = arr[j] % 4) {
  arr[j] = x;
 }
}
ready
bitwise
var j = arr.length;
var x;
while (j--) {
 if (x = (arr[j] & 3)){
  arr[j] = x;
 }
}
ready

Revisions

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