document.head

JavaScript performance comparison

Revision 7 of this test case created by Ryun shofner

Info

How much faster is the HTML5 document.head DOM tree accessor compared to its old-school variant, document.getElementsByTagName('head')[0]?

And to add tot his, is document.body any faster?

Preparation code

<script>
  document.head || (document.head = document.getElementsByTagName('head')[0]);

  var headList = document.getElementsByTagName('head');

  var test_tag = document.createElement('script');

  function insertEl(o) {
    o.appendChild(test_tag);
  }
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
document.getElementsByTagName('head')[0]
insertEl(document.getElementsByTagName('head')[0]);
pending…
document.head
insertEl(document.head);
pending…
querySelector
insertEl(document.querySelector('head'));
pending…
Live nodeList
insertEl(headList[0]);
pending…
document.body
insertEl(document.body);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment