From Nodelist to Array

JavaScript performance comparison

Revision 4 of this test case created by @murger

Preparation code

<div>
        <ul>
                <li id="item-2"><a href="#">item 2</a></li>
                <li id="item-1"><a href="#">item 1</a></li>
                <li id="item-3"><a href="#">item 3</a></li>
        </ul>
</div>
<script>
Benchmark.prototype.setup = function() {
    var nodes = document.getElementsByTagName('li');
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
slice, instance method
[].slice.call(nodes);
pending…
for loop
for (var i = 0, len = nodes.length, result = []; i < len; i++) {
        result.push(nodes[i]);
}

return result;
pending…
slice, prototype call
Array.prototype.slice.call(nodes);
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:

0 comments

Add a comment