for in vs jquery each (v2)

Revision 2 of this benchmark created by Geoff on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var test = [];
for(var i=0;i<10000;i++){
test.push(i+1);
}
//var k = test.length;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var j = 0; j < test.length; j++) {
  test[j]++;
}
ready
for in
for (j in test) {
  test[j]++;
}
ready
jquery each
$.each(test, function(j) {
  test[j]++;
});
ready
for with length variable
for (var j = 0, k = test.length; j < k; j++) {
  test[j]++;
}
ready

Revisions

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

  • Revision 2: published by Geoff on