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

Revision 36 of this benchmark created by rein on


Preparation HTML

<script src="https://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

Revisions

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