jQuery .find() vs. context selector (v9)

Revision 9 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>

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

Setup

document.createElement('article');
    var article = document.getElementsByTagName('article')[0];

Test runner

Ready to run.

Testing in
TestOps/sec
find method
var hasFrame = $(article).find('iframe').length > 0 ? true : false;

 
ready
context method
var hasFrame = $('iframe', article).length > 0 ? true : false;
ready
children method
var hasFrame = $(article).children('iframe').length > 0 ? true : false;
ready
context method 2
var hasFrame = $('.article iframe').length > 0 ? true : false;
ready

Revisions

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