Chaining vs two attr

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ol>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
</ol>
<script>
  var $li = $('li');
</script>

Preparation code output

  1. Item
  2. Item
  3. Item
  4. Item
  5. Item
  6. Item
  7. Item
  8. Item
  9. Item
  10. Item
  11. Item
  12. Item
  13. Item
  14. Item
  15. Item
  16. Item

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
One Atrributes
$li.attr({
  'target': '_blank',
  'title': 'Opens in a New Window'
});
pending…
Two Attributes
$li.attr('target', '_blank').attr('title', 'Opens in a New Window');
pending…

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

Compare results of other browsers

0 comments

Add a comment