Created
June 14, 2010 08:21
-
-
Save diogobaeder/437434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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