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

Revision 121 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p id="foo">
  Test
</p>
<script>
  var getId = function(id) {
      return document.getElementById(id)
      };
  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
function
$el = getId(foo)
ready

Revisions

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