Fastest way to select all expect the first one

JavaScript performance comparison

Test case created by Daminou

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="//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

  • I'm must not be selected
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies
  • I love ponies

Test runner

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

Java applet disabled.

Testing in unknown unknown
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…

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