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

Revision 38 of this benchmark created by aaronlks on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p id="foo">
  Test
</p>
<script>
  var wrap = function(id) {
      return $(document.getElementById(id))
      };
  var wrap2 = (function(window) {
    var doc = window.document;
    var jq = window.jQuery.fn.init;
    return function(id) {
      return new jq(doc.getElementById(id));
    };
  })(this);
</script>

Setup

var $el;

Teardown


    $el[0].id = "foo";
  

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
$el = $(document.getElementById('foo'));
ready
jQuery
$el = $('#foo');
ready
wrap
$el = wrap('foo')
ready
wrap2
$el = wrap2('foo')
ready
unwrap2
$el = new jQuery.fn.init(document.getElementById('foo'));
ready
window.document.getElementbyID
$el = $(window.document.getElementById('foo'));
ready
unwrap2 + window
$el = new jQuery.fn.init(window.document.getElementById('foo'));
ready

Revisions

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