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

Revision 4 of this benchmark created by Chris on


Description

Checking a filter that I'm about to write

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Using .filter
$('p').filter(function(index) {
  if (!$(this).parent().hasClass("testParentClass")) {
    return true;
  }
});
ready
Using .not
$('p').not(function(index) {
  if ($(this).parent().hasClass("testParentClass")) {
    return true;
  }
});
ready
Using :not
$('p:not(.testParentClass p)');
ready

Revisions

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