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

Revision 122 of this benchmark created on


Description

comparing selector speed

Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.js"></script>

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

Setup

var $body = $('body');

Test runner

Ready to run.

Testing in
TestOps/sec
cached scope method
var has = $body.find('ins').length > 0 ? true : false;
ready
global method
var has = $('ins').length > 0 ? true : false;
ready
uncached scope single selector
var has = $('body ins').length > 0 ? true : false;
ready
uncached scope 2 selectors
var has = $('body').find('ins').length > 0 ? true : false;
ready

Revisions

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