jQuery first child selection performance (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script>
 var content = '';
 for (var i = 0; i < 500; i++) {
  content += '<div id="lkjsf"' + i + '"></div>';
 }
 $('body').append('<div id="test" style="display:none">' + content + '</div>');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
first
$('#test :first')
ready
direct first
$('#test > :first')
ready
direct first-child
$('#test > :first-child')
ready
direct nth-child
$('#test > :nth-child(1)')
ready
eq
$('#test :eq(0)')
ready
find first
$('#test').find(':first')
ready
find direct first
$('#test').find('> :first')
ready
find element first
$('#test').find('div:first')
ready
find element eq
$('#test').find('div').eq(0)
ready
children first
$('#test').children(":first")
ready
children first in array
$($('#test').children()[0])
ready
children eq
$('#test').children().eq(0)
ready
children first-child
$('#test').children(":first-child")
ready
children nth-child
$('#test').children(":nth-child(1)")
ready

Revisions

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