getElementsByClassName VS jQuery('.class') (v135)

Revision 135 of this benchmark created on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script>
!function($){
        $.clss = function(c){
                return $(document.getElementsByClassName(c));
        }
}($);
</script>

<ul>
<li class="foo"></li>
<li class="bar"></li>
<li class="foo"></li>
<li class="bar"></li>
<li class="foo"></li>
<li class="bar"></li>
</ul>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
$(document.getElementsByClassName('foo'));
ready
jQuery Selector
$('.foo');
ready
Custom Method
function _(c){
    return jQuery(document.getElementsByClassName(c));
}
_('foo');
 
ready
$ Custom Method
function _(c){
    return $(document.getElementsByClassName(c));
}
_('foo');
 
ready
jQuery Window Object
$('.foo');
$('.bar');
ready
realgetElementsByClassName
document.getElementsByClassName('foo');
ready
typeof
if(typeof (document.getElementsByClassName('foo')) === "undefined"){}
ready
$.clss
$.clss('foo')
ready

Revisions

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