hasClass (v4)

Revision 4 of this benchmark created by Bruno Garcia on


Description

This will test a number of different alternatives for a hasClass function

Preparation HTML

<div id="test" class="a"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//github.com/dgalarza/RaptorJS/raw/master/src/raptor.pack.js"></script>
<script>
  // RaptorJS
  var $p = raptor.pack; // to keep prop look-ups equal with competition
  var raptor_test = document.getElementById('test');
  var jQuery_test = $('#test');
  
  Element.prototype.matchesSelector = Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
RaptorJS
$p.hasClass('a', raptor_test);
ready
jQuery
jQuery_test.hasClass('a');
ready
jQuery Cached
$(raptor_test).hasClass('a');
ready
String search
function hasClass(element, className) {
 return (" " + element.className + " ").indexOf(" " + className + " ") != -1;
}

hasClass(raptor_test, "a");
ready
matchesSelector
raptor_test.matchesSelector(".a");
ready

Revisions

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

  • Revision 1: published by bbarr on
  • Revision 2: published by dgalarza on
  • Revision 3: published by Bruno Garcia on
  • Revision 4: published by Bruno Garcia on
  • Revision 10: published on