$("#id") vs $(document.getElementById) (v19)

Revision 19 of this benchmark created by ckozl on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="LOL">
</div>
<script>
  var $el, $ref = document.getElementById('LOL');
</script>

Setup

$el = null;

Teardown


    if ($el !== $ref) {
      throw Error('cannot test');
    }
  

Test runner

Ready to run.

Testing in
TestOps/sec
#id
$el = $("#LOL")[0];
ready
tag + attrib
$el = $("div[id=LOL]")[0];
ready
attrib
$el = $("[id=LOL]")[0];
ready
tag + id
$el = $('div#LOL')[0];
ready
queryselectorall
$el = document.querySelectorAll('#LOL')[0];
ready
queryselector
$el = document.querySelector('#LOL')[0];
ready
getElementById
$el == document.getElementById("LOL");
ready
native chrome global var from ID
$el = LOL;
ready
derp
$el = window.LOL;
ready

Revisions

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