Fastest way to select all expect the first one

JavaScript performance comparison

Revision 6 of this test case created by TrueBlueAussie

Preparation code

<ul>
<li>I'm must not be selected</li>
<li>I love ponies</li><li>I love ponies</li><li>I love ponies</li>
<li>I love ponies</li><li>I love ponies</li><li>I love ponies</li>
<li>I love ponies</li><li>I love ponies</li><li>I love ponies</li>
<li>I love ponies</li><li>I love ponies</li><li>I love ponies</li>
<li>I love ponies</li><li>I love ponies</li><li>I love ponies</li>
</ul>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

      
<script>
Benchmark.prototype.teardown = function() {
  if ($('li:visible').lenght !== 1) {
    alert("Something went wrong");
  }
  
  $('li').show();

};
</script>

Preparation code output

<ul> <li>I'm must not be selected</li> <li>I love ponies</li><li>I love ponies</li><li>I love ponies</li> <li>I love ponies</li><li>I love ponies</li><li>I love ponies</li> <li>I love ponies</li><li>I love ponies</li><li>I love ponies</li> <li>I love ponies</li><li>I love ponies</li><li>I love ponies</li> <li>I love ponies</li><li>I love ponies</li><li>I love ponies</li> </ul>

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
not :first
$("li:not(:first)").hide();
pending…
not eq0
$("li:not(:eq(0))").hide();
pending…
After not :eq
$("li").not(":eq(0)").hide();
pending…
:gt
$("li:gt(0)").hide();
pending…
Slice
$("li").slice(1).hide();
pending…
not(":first")
$("li").not(":first").hide();
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.

0 Comments