jQuery.each vs. for loop (v163)

Revision 163 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var a = [1,2,3,4,5,6,7,8,9,10,11];
  var e;
  function getRandomInt(){
    return Math.ceil(Math.random() * 10000);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.each
$.each(a, function() {
  window.e = this + getRandomInt();
});
ready
for loop
for (var i = 0, len = a.length; i < len; ++i) {
  window.e = a[i] + getRandomInt();
};
ready
Array.forEach
a.forEach(function(x) {
   window.e = x + getRandomInt();
});
ready

Revisions

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