NodeList vs. Array

JavaScript performance comparison

Test case created by Markus Nix

Preparation code

<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
      
<script>
Benchmark.prototype.setup = function() {
  var i,
      divs_nl  = document.getElementsByTagName('div'),
      l_nl     = divs_nl.length,
      divs_arr = Array.prototype.slice.call(divs_nl),
      l_arr    = divs_arr.length;

};
</script>

Preparation code output

<div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div>

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
NodeList
for (i = 0; i < l_nl; i++) {
  divs_nl[i].appendChild(document.createElement('p'));
}
pending…
Array Object
for (i = 0; i < l_arr; i++) {
  divs_arr[i].appendChild(document.createElement('p'));
}
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