getElementById VS jQuery('#id') (v78)

Revision 78 of this benchmark created by weliyt on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<p id="foo">
  Test
</p>
<p id="bar">
  bars</p>

Test runner

Ready to run.

Testing in
TestOps/sec
Basic getElementById
document.getElementById('foo');
document.getElementById('bar');
ready
#1 Method Wrapped
function _(id) {
  return document.getElementById(id);
}
_("foo");
_("bar");
ready
#1 jQuery Object Returned
function _(id) {
  return $(document.getElementById(id));
}
_('foo');
_('bar');
ready
#1 DOM Returned, then jQuery Wrapped
function _(id) {
  return $(document.getElementById(id));
}
$(_('foo'));
$(_('bar'));
ready
jQuery Selector
$('#foo');
$('#bar');
ready

Revisions

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