jquery .each VS for loops (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>

Setup

var collection = {
      1: 'bum',
      2: 'poo',
      3: 'pee',
      4: 'whore',
      5: 'hives',
      6: 'dicks',
      iLike: 'cheese'
    };
    var value;

Test runner

Ready to run.

Testing in
TestOps/sec
$.each
$.each(collection, function(key, val) {
  // code...
});
ready
_.each
_.each(collection, function(val, key) {
  // code...
});
ready
for ( in )
for (var i in collection) {
  if (collection.hasOwnProperty(i)) {
    // code...
  }
}
ready
for (;;)
for (var i = 0, len = collection.length; i < len; i++) {
  // code...
}
ready
[].forEach
[].forEach.call(collection, function(val, key) {
  // code...
});
ready

Revisions

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