convert HTML collection into array

JavaScript performance comparison

Revision 3 of this test case created by convert HTML collection into array 2

Preparation code

<html>
<body>
<form>
<div>
<input type="text" name="username" value="username"/>
<input type="password" name="password" value"password"/>
</div>
<input type="button" value="login"/>
</form>
</body>
</html>
    

Preparation code output

<html> <body> <form> <div> <input type="text" name="username" value="username"/> <input type="password" name="password" value"password"/> </div> <input type="button" value="login"/> </form> </body> </html>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
HTML collection
var objs=document.forms[0].elements;

for(var i=0;i<objs.length;i++){
 alert(objs[i].value);
}
pending…
convert HTML collection into Array

var objsArray=Array.prototype.slice.call(document.forms[0].elements);

for(var i=0;i<objsArray.length;i++){
 alert(objsArray[i].value);
}
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.

0 Comments