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

Revision 8 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
  fatArray = [];
  size = 1000;
  for(var i = 0; i < size; i++) {
    fatArray[i] = Math.floor(Math.random() * size);
  }
</script>

Setup

var min = Infinity;
    
    function compare(index, value) {
      if (min > value) {
        min = value;
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
JQuery
$.each(fatArray, compare);
ready
for
for (var i = 0; i < fatArray.length; i += 1) {
  var val = fatArray[i];
  if (min > val) {
    min = val;
  }
}
ready
_.each
_.each(fatArray, compare);
ready
forEach
fatArray.forEach(compare);
ready
while
var i = fatArray.length;
while(i--) {
  var val = fatArray[i];
  if (min > val) {
    min = val;
  }
}
ready
for length
var val;
for (var i = 0, l = fatArray.length; i < l; i ++) {
  val = fatArray[i];
  if (min > val) {
    min = val;
  }
}
ready

Revisions

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