JQuery each vs for loop (v55)

Revision 55 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
for
function getArrayMin(array) {
  var min = -1;
  for (var i = 0; i < array.length; i++) {
    var val = array[i];
    if (min < 0 && val > 0) {
      min = val;
      continue;
    }
    if (val > 0 && min > val) {
      min = val
      continue;
    }
  }
  return min;
};


getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
ready
reverse for
function getArrayMin(array) {
  var min = -1;
  for (var i = array.length - 1; i >= 0; i--) {
    var val = array[i];
    if (min < 0 && val > 0) {
      min = val;
      continue;
    }
    if (val > 0 && min > val) {
      min = val
      continue;
    }
  }
  return min;
};

getArrayMin([-5, -1, 2, 0, 0, 8, 1248, 19238, 924, 9, 11, 10, 0]);
ready
for with cached length
function getArrayMin(array) {
  var min = -1;
  for (var i = 0, max = array.length; i < max; i++) {
    var val = array[i];
    if (min < 0 && val > 0) {
      min = val;
      continue;
    }
    if (val > 0 && min > val) {
      min = val
      continue;
    }
  }
  return min;
};


getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
ready

Revisions

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