convert HTML collection into array

JavaScript performance comparison

Revision 11 of this test case created by Matt Newman

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>
<script>
Benchmark.prototype.setup = function() {
    var objs = document.forms[0].elements;
    var objsArray = Array.prototype.slice.call(objs);
   
};
</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
HTML Collection
for (var i = 0; i < objs.length; i++) {
  alert(objs[i].value);
}
pending…
Convert HTML Collection into Array
for (var i = 0; i < objsArray.length; i++) {
  alert(objsArray[i].value);
}
pending…
HTML Collection Decrement
var i=objs.length; for(; i--;){alert(objs[i].value)}
pending…
Convert HTML Collection into Array with a Decrement
var i=objsArray.length; for(; 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. Here’s a list of current revisions for this page:

0 comments

Add a comment