el.dhildren[0] vs loop nextSiblings

JavaScript performance comparison

Test case created by shwups

Preparation code

<div id="a">
a
<div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div>
</div>
<script>
Benchmark.prototype.setup = function() {
    var loop = function(el){
                do {
                        if(el.nodeType===1){
                                return el;
                        }
                        el = el.nextSibling;
        } while(el);
        return null;
    }
    var child0 = function(el){
        return el.children[0];
    }
   
    var el = document.getElementById('a')
};
</script>

Preparation code output

a

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
children[0]
var x = child0(el)
pending…
loop nextSibling
var x = loop(el)
pending…

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

Compare results of other browsers

0 comments

Add a comment