jquery .each vs .find attribute (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul id="testme">
  <li value="1">
  </li>
  <li value="12">
  </li>
  <li value="122">
  </li>
  <li value="1222">
  </li>
  <li value="12222">
  </li>
  <li value="122222">
  </li>
  <li value="1222222">
  </li>
  <li value="12222222">
  </li>
  <li value="122222222">
  </li>
  <li value="1222222222">
  </li>
  <li value="12222222222">
  </li>
  <li value="20">
  </li>
</ul>

Setup

var MyValue = "20";

Test runner

Ready to run.

Testing in
TestOps/sec
each
$("#testme li").each(function() {
  if ($(this).value == MyValue) {
    console.log("true");
  }
});
ready
find
$("#testme").find("[value=" + MyValue + "]").each(function() {
  console.log("true");
});
ready
each of find
$.each($("#testme").find("[value=" + MyValue + "]"), function() {
  console.log("true");
});
ready

Revisions

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