node-collection-to-array

JavaScript performance comparison

Test case created by Dmitry Podgorniy

Preparation code

<!-- 20 links -->
<a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a>
      
<script>
Benchmark.prototype.setup = function() {
  var live_collection = document.links;
  var get_by_tag = document.getElementsByTagName('a');
  var dead_collection = document.querySelectorAll('a');

};
</script>

Preparation code output

<!-- 20 links --> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a> <a href="#">link</a>

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
Iterate
function to_array (obj) {
	var i, length, res;

	length = obj.length;
	res = [];
	for (i = 0; i < length; i += 1) {
		res.push(obj[i]);
	}
	return res;
}
to_array(live_collection)
pending…
slice
function to_array (obj) {
	return Array.prototype.slice.call(obj);
}

to_array(live_collection);
pending…
iterate (live collection)
function to_array (obj) {
	var i, length, res;

	length = obj.length;
	res = [];
	for (i = 0; i < length; i += 1) {
		res.push(obj[i]);
	}
	return res;
}
to_array(get_by_tag)
pending…
iterate (dead collection)
function to_array (obj) {
	var i, length, res;

	length = obj.length;
	res = [];
	for (i = 0; i < length; i += 1) {
		res.push(obj[i]);
	}
	return res;
}
to_array(dead_collection)
pending…
slice (live collection)
function to_array (obj) {
	return Array.prototype.slice.call(obj);
}

to_array(get_by_tag);
pending…
slice (dead collection)
function to_array (obj) {
	return Array.prototype.slice.call(obj);
}

to_array(dead_collection);
pending…

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

Compare results of other browsers

0 Comments

link link link link link link link link link link link link link link link link link link link link link link