$.hasClass vs _.detect

Benchmark created by Kai on


Description

Testing jQuery's hasClass method against underscore's detect as found in Backbone.js.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
<div id="test" class="tester checker">Test</div>

Test runner

Ready to run.

Testing in
TestOps/sec
$.hasClass
if ($('#test').hasClass('checker')) {
 $('#test').html('true');
}
ready
_.detect
if (_.detect(document.getElementById('test').classList, function(class) {
 return (class == 'checker');
})) {
 $('#test').html('true');
}
ready

Revisions

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