From Nodelist to Array

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<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>
var toArray = this.toArray = function(list) {
        var retval = [];
        for (var i=list.length; i--;) {
                retval.push(list[i]);
        }
        return retval;
};
var a = 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
1°) Native fn from Nodelist to Array
[].slice.call(a);
pending…
2°) Custom fn from Nodelist to Array
toArray(a);
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