firstElementChild vs firstChild + if nodeType === 1

Benchmark created by burningbroccoli on


Preparation HTML

<div id="testnode">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

Setup

var node = document.getElementById('testnode')
    var child

Test runner

Ready to run.

Testing in
TestOps/sec
firstElementChild
child = node.firstElementChild
ready
firstChild + if
var childNode = node.firstChild
if (childNode.nodeType === 1) {
  child = childNode
}
ready

Revisions

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

  • Revision 1: published by burningbroccoli on