firstChild vs CSS selector

JavaScript performance comparison

Test case created by Vyacheslav

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="geolocation" class="chzn-container chzn-container-single" style="width: 220px;" title=""><a href="javascript:void(0)" class="chzn-single" tabindex="-1"><span>Россия • Москва</span><div><b></b></div></a>
    <div class="chzn-drop" style="display: none; left: 0px; width: 220px; top: 44px;">
        <div class="chzn-search">
            <input type="text" id="chosen-search" autocomplete="off" style="width: 212px;">
        </div>
    </div>
</div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
firstchild
$('#geolocation')[0].firstChild.firstChild.textContent;
pending…
CSS selector
$('#geolocation > a > span')[0].textContent;
pending…
CSS selector 2
$('#geolocation > a > span').text();
pending…
children()[0].textContent
$('#geolocation').children().children()[0].textContent
pending…
children().text()
$('#geolocation').children().children().text()
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment