JQuery each vs for loop vs _.each (lodash)

JavaScript performance comparison

Revision 16 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for
function getArrayMin(array) {
  var min = array[0],
    len = array.length,
    i, val;
  for (i = 1; i < len; i += 1) {
    val = array[i];
    if (min > val) {
      min = val;
    }
  }
  return min;
};


getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
pending…
_.each
function getArrayMin(array) {
  var min = -1;
  _.each(array, function(idx, val) {
    if (min < 0 && val > 0) {
      min = val;
      return true;
    }
    if (val > 0 && min > val) {
      min = val
      return true;
    }
  });
  return min;
};


getArrayMin([0, 10, 11, 9, 924, 19238, 1248, 8, 0, 0, 2, -1, -5]);
pending…
JQuery 2
function getArrayMin(array) {
  var min = array[0];
  $.each(array, function(idx, val) {
    if (min > val) {
      min = val;
    }
  });
  return min;
};


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


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

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment