jQuery vs. DOM again (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<form id="someForm">
  <input type="checkbox" />
  <input type="checkbox" />
  <input type="checkbox" checked/>
  <input type="checkbox" checked/>
  <input type="checkbox" />
  <input type="checkbox" checked/>
  <input />
  <input />
  <input />
  <input />
  <input />
</form>

Setup

// utility function
    window.toArray = function(obj) {
      var arr = [];
      for (var i = 0, len = obj.length; i < len; i++) {
        arr[i] = obj[i];
      }
      return arr;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
DOM
var form = document.getElementById("someForm");

var checked = toArray(form.elements).some(function(el) {
  return el.type === "checkbox" && el.checked;
});
ready
jQUery
$(':checkbox:checked', '#someForm').length;
ready

Revisions

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