document.head (v7)

Revision 7 of this benchmark created by Ryun shofner on


Description

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 HTML

<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

Ready to run.

Testing in
TestOps/sec
document.getElementsByTagName('head')[0]
insertEl(document.getElementsByTagName('head')[0]);
ready
document.head
insertEl(document.head);
ready
querySelector
insertEl(document.querySelector('head'));
ready
Live nodeList
insertEl(headList[0]);
ready
document.body
insertEl(document.body);
ready

Revisions

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

  • Revision 1: published by Mathias Bynens on
  • Revision 2: published by Charles Lehner on
  • Revision 3: published by kangax on
  • Revision 4: published by stefaan on
  • Revision 5: published on
  • Revision 6: published on
  • Revision 7: published by Ryun shofner on