document.head
JavaScript performance comparison
Info
How much faster is the HTML5 document.head DOM tree accessor compared to its old-school variant, document.getElementsByTagName('head')[0]?
Preparation code
<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
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
document.getElementsByTagName('head')[0] |
|
pending… |
document.head |
|
pending… |
document.head via prototype |
|
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:
- Revision 1: published by Mathias Bynens and last updated
- Revision 2: published by Charles Lehner
- Revision 3: published by kangax and last updated
- Revision 4: published by stefaan
- Revision 5: published
- Revision 6: published
- Revision 7: published by Ryun shofner
0 comments