$(element) vs $('query') x .find() vs. query context

JavaScript performance comparison

Revision 25 of this test case created by tiffon

Info

comparing selector speed

Preparation code

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

<article id="uniquely-id-this-article">
<p>A test</p>
<p><iframe></iframe></p>
<p>This is text</p>
</article>
 
<script>
Benchmark.prototype.setup = function() {
    var element = document.querySelector('body');
    var $element = $(element);
    var $query = $('body');
   
};
</script>

Preparation code output

A test

This is text

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$element find method
var hasFrame = $element.find('iframe').length > 0 ? true : false;
pending…
$('some query') find method
var hasFrame = $query.find('iframe').length > 0 ? true : false;
pending…
context with HTMLElement
var hasFrame = $('iframe', element).length > 0 ? true : false;
pending…
context with $(HTMLElement)
var hasFrame = $('iframe', $element).length > 0 ? true : false;
pending…
context with $('some query')
var hasFrame = $('iframe', $query).length > 0 ? true : false;
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