Chaining vs two attr

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://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

<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>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
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

  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