convert HTML collection into array
JavaScript performance comparison
Info
Some of the previous revisions were incrementing the amount of children in parentdiv after each loop, resulting in slower code the longer the benchmark ran.
This revision does not have that issue.
Preparation code
<div id="parent">
</div>
<script type=text/js>
var parentNode = document.getElementById('parent'), i;
for (length = 100, i = length; i > length; i--) {
parentNode.appendChild(document.createElement('div'));
}
</script>
<script>
Benchmark.prototype.setup = function() {
var parentNode = document.getElementById('parent'), objs = parentNode.getElementsByTagName('div');
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
HTML collection |
|
pending… |
convert HTML collection into Array |
|
pending… |
convert HTML collection into Array with Array.slice |
|
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:
- Revision 1: published
- Revision 2: published
- Revision 3: published by convert HTML collection into array 2
- Revision 4: published by Cong Liu
- Revision 6: published by Cong Liu
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published by Cong Liu
0 comments