Skip to content

Instantly share code, notes, and snippets.

@diogobaeder
Created June 14, 2010 08:21
Show Gist options
  • Save diogobaeder/437434 to your computer and use it in GitHub Desktop.
Save diogobaeder/437434 to your computer and use it in GitHub Desktop.
/**
* Use the code below as a reference if you're sure you're using
* elements' ID's. In my system, the pure version ended in 243ms while
* the accelerated version ended in 33ms. The speed difference is not
* noticeable for a small number of traversals, though.
*/
jQuery(function(){
(function($, doc){
var nElements = 100, iterations = 10000;
var i = iterations, j = nElements;
console.time("pure jQuery");
while (i--) {
$("p" + i);
}
console.timeEnd("pure jQuery");
i = iterations; j = nElements;
console.time("accelerated jQuery");
while (i--) {
$(doc.getElementById("p" + i));
}
console.timeEnd("accelerated jQuery");
})(jQuery, document);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment