document.head (v3)

Revision 3 of this benchmark created by kangax on


Description

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

Preparation HTML

<script>
  document.head = document.head || document.getElementsByTagName('head')[0];
  
  Object.defineProperty(Document.prototype, 'head2', {
   get: function() {
    return this.head || this.getElementsByTagName('head')[0]
   }
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
document.getElementsByTagName('head')[0]
document.getElementsByTagName('head')[0];
ready
document.head
document.head;
ready
document.head via prototype
document.head2;
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