NodeList To Array (v27)

Revision 27 of this benchmark created by Stereokai on


Description

http://stackoverflow.com/questions/3199588/fastest-way-to-convert-javascript-nodelist-to-array

Preparation HTML

<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><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><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><div></div><div></div><div></div><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<script>
  var nl = document.getElementsByTagName('*');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.slice.call
var arr = Array.prototype.slice.call(nl);
ready
push
var arr = [];
for (var i = 0, n; n = nl[i]; ++i) arr.push(n);
ready
single for
var l = []; // Will hold the array of Node's
for (var i = 0, ll = nl.length; i != ll; l.push(nl[i++]));
ready
set length first
var arr = [];
for (var i = 0, ref = arr.length = nl.length; i < ref; i++) {
 arr[i] = nl[i];
}
ready
set length first 2
var arr = [],
  len = nl.length,
  i;

for (i = 0; i < len; i += 1) {
 arr[i] = nl[i];
}
ready
Terse While new Array
var l=nl.length, arr = new Array(l);
while(l--){arr[l]=nl[l]};
ready
Push.apply
var arr = [];
arr.push.apply(arr, nl);
ready
Array.unshift
// nl is the nodelist
var arr = [];
for (var i = nl.length; i--; arr.unshift(nl[i]));
ready
Bitwise operation
var arr = [];
for (var i=0, l=nl.length >>> 0; i++ !==l; arr[i] = nl[i]);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.