Comparing jQuery's .filter VS .not VS :not (v9)

Revision 9 of this benchmark created by Bruno G. on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p>
  Single P
</p>
<p class="first-class">
  P with class
</p>
<p id="first-id">
  P with it
</p>
<p class="second-class" id="second-id">
  P with class and ID
</p>

Test runner

Ready to run.

Testing in
TestOps/sec
Using .filter
$('p').filter(function(index) {
  if (!$(this).attr("class") && !$(this).attr("id")) {
    return true;
  }
});
ready
Using .not
$('p').not(function(index) {
  if ($(this).attr("class") || $(this).attr("id")) {
    return true;
  }
});
ready
Using :not
$('p:not([id],[class])');
ready
Simple .not
$('p').not('.second-class');
ready
Simple :not
$('p:not(.second-class)');
ready
Simple .filter :not
$('p').filter(':not(.second-class)');
ready

Revisions

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