jQuery Each vs JavaScript For

JavaScript performance comparison

Test case created

Preparation code

<ul>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
  <li>
    test
  </li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    $subStatusList = $('li')
};
</script>

Preparation code output

  • test
  • test
  • test
  • test
  • test
  • test
  • test
  • test
  • test

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery Each
$subStatusList.each(function(index, li) {
  $li = $(li)
});
pending…
JavaScript For
for (var i = 0, l = $subStatusList.length; i < l; i++) {
  li = $subStatusList[i]
  $li = $(li)
}
pending…
CoffeeScript For
var $li, li, _i, _len;

for (_i = 0, _len = $subStatusList.length; _i < _len; _i++) {
  li = $subStatusList[_i];
  $li = $(li);
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment