jQuery .find() vs. context selector vs non-context selector (v24)

Revision 24 of this benchmark created on


Description

comparing selector speed

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<p><ins></ins></p>

<div>
        <p>A test</p>
        <p><ins></ins></p>
        <p>This is text</p>
</div>

<p><ins></ins></p>

<div>
        <p>A test</p>
        <p><ins></ins></p>
        <p>This is text</p>
</div>
 

<p><ins></ins></p>

<div>
        <p>A test</p>
        <p><ins></ins></p>
        <p>This is text</p>
        <div>
                <p>A test</p>
                <p><ins></ins></p>
                <p>This is text</p>
                <div>
                        <p>A test</p>
                        <p><ins></ins></p>
                        <p>This is text</p>
                        <div>
                                <p>A test</p>
                                <p><ins></ins></p>
                                <p>This is text</p>
                                <div>
                                        <p>A test</p>
                                        <p><ins></ins></p>
                                        <p>This is text</p>
                                        <div>
                                                <p>A test</p>
                                                <p><ins></ins></p>
                                                <p>This is text</p>
                                                        <div>
                                                                <p>A test</p>
                                                                <p><ins></ins></p>
                                                                <p>This is text</p>
                                                        </div>
                                        </div>
                                </div>
                        </div>
                </div>
        </div>
</div>
                
<div>
        <p>A test</p>
        <div>
                <div>
                        <div>
                                <p><ins></ins></p>
                        </div>
                </div>
        </div>
        <p>This is text</p>
</div>

Setup

var $article = $('div');
    var article = $article[0];

Test runner

Ready to run.

Testing in
TestOps/sec
find method (node context)
var has = $(article).find('ins').length > 0 ? true : false;
ready
find method (jquery context)
var has = $($article).find('ins').length > 0 ? true : false;
ready
context node
var has = $('ins', article).length > 0 ? true : false;
ready
context jQuery
var has = $('ins', $article).length > 0 ? true : false;
ready
context jQuery[0]
var has = $('ins', $article[0]).length > 0 ? true : false;
ready
cascade
var has = $('div ins').length > 0 ? true : false;
ready
context (no cached)
var has = $('ins', 'div').length > 0 ? true : false;
ready
find method without >
var has = !!$(article).find('ins').length;
ready

Revisions

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