jQuery .find() vs. context selector

JavaScript performance comparison

Revision 90 of this test case created by

Preparation code

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

<article>
<p>A test</p>
<p><iframe id="123"></iframe></p>
<p>This is text</p>
</article>
<div class="myOuterDivClass" id="myOuterDivId">
<h4 data-i18n="CallContact">Call Contact:</h4>
    <span class="contactId">_000000_</span>
    <span class="skillName">_IB Skill_</span>
    <span class="totalContactTime">_00:00:00_</span>
    <hr/>
    <div class="status">
        <span class="stateName">_Disconnected_</span>
        <span class="ani">_123456789_</span>
        <span class="stateTime">_00:00:00_</span>
        
    </div>
    <div class="linked">
        <span>Linked!</span>        
		<button class="amdOverrideMachine">Machine</button>
        <button class="amdOverrideVoicemail">Voicemail</button>
    </div>
        <span class="label">_label_</span>
        <div class="otherInformation"></div>
    <hr/>
    <button class="accept">Accept</button>
	<button class="resume" data-i18n="Resume"></button>
    <button class="hold" data-i18n="Hold"></button>
    <button class="end" data-i18n="HangUp"></button>
    <button class="record" data-i18n="Record"></button>
    <button class="mask" data-i18n="Mask"></button>
    <button class="unmask" data-i18n="Unmask"></button>
    <button class="add" data-i18n="Add"></button>
    <div id="__UID__transfer" style="border:solid; border-width: 2px">
        <button class="transfer" data-i18n="Transfer"></button>
        <button class="conference" data-i18n="Conference"></button>
    </div>
    <div class="confirmationRequired" style="border:solid; border-width:2px;">
        <button class="acceptPreview">Accept</button>
        <button class="rejectPreview">Reject</button>
        <span class="previewCountdown">00:00:00</span>
    </div>
    <div class="dispositionSectionElement"></div>
    <div class="indcatorDiv"></div>
</div>
      
<script>
Benchmark.prototype.setup = function() {
  var article = document.querySelector('article');

};
</script>

Preparation code output

<article> <p>A test</p> <p><iframe id="123"></iframe></p> <p>This is text</p> </article> <div class="myOuterDivClass" id="myOuterDivId"> <h4 data-i18n="CallContact">Call Contact:</h4> <span class="contactId">_000000_</span> <span class="skillName">_IB Skill_</span> <span class="totalContactTime">_00:00:00_</span> <hr/> <div class="status"> <span class="stateName">_Disconnected_</span> <span class="ani">_123456789_</span> <span class="stateTime">_00:00:00_</span> </div> <div class="linked"> <span>Linked!</span> <button class="amdOverrideMachine">Machine</button> <button class="amdOverrideVoicemail">Voicemail</button> </div> <span class="label">_label_</span> <div class="otherInformation"></div> <hr/> <button class="accept">Accept</button> <button class="resume" data-i18n="Resume"></button> <button class="hold" data-i18n="Hold"></button> <button class="end" data-i18n="HangUp"></button> <button class="record" data-i18n="Record"></button> <button class="mask" data-i18n="Mask"></button> <button class="unmask" data-i18n="Unmask"></button> <button class="add" data-i18n="Add"></button> <div id="__UID__transfer" style="border:solid; border-width: 2px"> <button class="transfer" data-i18n="Transfer"></button> <button class="conference" data-i18n="Conference"></button> </div> <div class="confirmationRequired" style="border:solid; border-width:2px;"> <button class="acceptPreview">Accept</button> <button class="rejectPreview">Reject</button> <span class="previewCountdown">00:00:00</span> </div> <div class="dispositionSectionElement"></div> <div class="indcatorDiv"></div> </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
context method
var outer = $('.myOuterDivId');
pending…
find method
var outer = $('.myOuterDiv');
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.

0 Comments

A test

This is text

Call Contact:

_000000_ _IB Skill_ _00:00:00_
_Disconnected_ _123456789_ _00:00:00_
Linked!
_label_

00:00:00