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

Revision 134 of this benchmark created on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
! function($) {
   $.id = function(id) {
      return $(document.getElementById(id));
   }
}(jQuery);
! function($) {
   $.id2 = function(id) {
      return $(document.getElementById(id));
   }
}($);

function getObjectById(id){
        return jQuery(document.getElementById(id));
}
</script>
<div id="foo">
  Test
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
$.id
$.id('foo')
ready
getObjectById
getObjectById('foo')
ready
$(document.getElementById())
$(document.getElementById('foo'))
ready
jQuery
$('#foo')
ready
$.id2
$.id2('foo')
ready

Revisions

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