document.getElementById VS Jquery $('#') JQuery 2 (v33)

Revision 33 of this benchmark created by RT on


Description

Comparison for $('#id') VS document.getElementById('id');

Preparation HTML

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

Setup

window.nativeFoo = document.getElementById('foo');
    window.$foo = $('#foo');
    window.$nativeFoo = $(document.getElementById('foo'));

Test runner

Ready to run.

Testing in
TestOps/sec
document.getElementById('id')
document.getElementById('foo');
ready
jQuery $('#id')
$('#foo');
ready
jQuery + native JS
$(document.getElementById('foo'));
ready
jQuery + cached native node
$(nativeFoo);
ready
Cached jQuery
$foo;
ready
Cached jQuery(nativeElement)
$nativeFoo;
ready

Revisions

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