getElementById VS jQuery('#id') 2.1.1 (v142)

Revision 142 of this benchmark created on


Preparation HTML

<script src="https://code.jquery.com/jquery-git2.js"></script>
<p id="bar21">
  bars</p>
<p>tesxt</p>
<div id="qab21">aba</div>
<div>paragaranph<div>sub</div>post</div>
<p>tesxt</p>
<div>aba</div>
<div>paragaranph<div>sub</div>post</div>
<p id="ch211">tesxt</p>
<div id="baba21">aba</div>
<div>paragaranph<div>sub</div>post</div>

<p id="bar1">
  bars</p>
<p>tesxt</p>
<div id="qab1">aba</div>
<div>paragaranph<div>sub</div>post</div>
<p>tesxt</p>
<div>aba</div>
<div>paragaranph<div>sub</div>post</div>
<p id="ch11">tesxt</p>
<div id="baba1">aba</div>
<div>paragaranph<div>sub</div>post</div>
<p id="foo">
  Test
</p>
<p id="bar">
  bars</p>
<p>tesxt</p>
<div id="qab">aba</div>
<div>paragaranph<div>sub</div>post</div>
<p>tesxt</p>
<div>aba</div>
<div>paragaranph<div>sub</div>post</div>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
$(document.getElementById('foo'));
ready
jQuery Selector
$('#foo');
ready
Custom Method
function _(id){
    return jQuery(document.getElementById(id));
}
_('foo');
 
ready
$ Custom Method
function _(id){
    return $(document.getElementById(id));
}
_('foo');
 
ready
jQuery Window Object
$('#foo');
$('#bar');
ready
realgetelementbyid
document.getElementById('foo');
ready
#bar
$('#bar');
ready
p#bar
$('p#bar');
ready

Revisions

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