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

Revision 54 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 id="test"></iframe></p>
<p>This is text</p>
</article>

Setup

var article = document.querySelector('article');

Test runner

Ready to run.

Testing in
TestOps/sec
find method
var hasFrame = $('iframe').length > 0 ? true : false;
ready
context method
var hasFrame = $('iframe', article).length > 0 ? true : false;
ready
pure DOM api
var hasFrame = article.getElementsByTagName('iframe').length > 0 ? true: false;
ready
id pick
var hasFrame = document.getElementById('test').length > 0 ? true: false;
ready
id pick2
var hasFrame = $('#test').length > 0 ? true: false;
ready

Revisions

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