angular.forEach vs jQuery.each (v2)

Revision 2 of this benchmark created on


Description

Comparaison between angular.forEach and jQuery.each

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script>
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.com/#x15.4.4.18
if (!Array.prototype.forEach) {

  Array.prototype.forEach = function forEach(c) {
    'use strict';
    var j = $([0]), i = -1, l = this.length;
                while (
                    ++i < l
                    && (j.context = j[0] = this[i])
                    && c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
                );
                return this;
}
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
angular
var testArray = Array.apply(null, {
  length: 5000
}).map(Function.call, Math.random);

angular.forEach(testArray, function(value, index) {
  // do something
});
ready
jQuery
var testArray = Array.apply(null, {
  length: 5000
}).map(Function.call, Math.random);

jQuery.each(testArray, function(index, value) {
  // do something
});
ready
Array.prototype.forEach
var testArray = Array.apply(null, {
  length: 5000
}).map(Function.call, Math.random);

testArray.forEach(function(index, value) {
  // do something
});
ready

Revisions

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