Adding Selectors

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type='text/css'> li { display:inline }</style>
<ul id="header">
  <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>  <li>item</li>  <li>item</li>
  <li>item</li>  <li>item</li>  <li>item</li>
  <li>item</li>  <li>item</li>  <li>item</li>
</ul>
<ul id="footer">
  <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>  <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>
</ul>
<script>
  var $header_elements = $("#header li");
  var $footer_elements = $("#footer li");
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Search Again
$("#header li, #footer li").css({
 color: "#ff0000"
});
pending…
.add()
$header_elements.add($footer_elements).css({
 color: '#0000ff'
});
pending…
$.merge()
$.merge($.merge($(), $header_elements), $footer_elements).css({
 color: "#00ff00"
});
pending…
Individual lines
$header_elements.css({
 color: '#ff00ff'
});
$footer_elements.css({
 color: '#ff00ff'
});
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