filter performance (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id='id'>
 <ul id='ul'>
  <li id='1' class="">a</li>
  <li id='2' class="">a</li>
  <li id='3' class="">a</li>
  <li id='4' class="select">a</li>
  <li id='5' class="">a</li>
 </ul>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
using filter
$("#ul > li").filter(function(index) {
 return $(this).hasClass("select");
}).removeClass("select");
ready
using selector
$("ul > li").removeClass("select");
ready
using each loop
$("#ul > li").each(function(index, element) {
 if ($(this).hasClass("select")) $(this).removeClass("select");
});
ready
$('li.select')
$('li.select').removeClass('select')
ready

Revisions

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