Created
November 16, 2012 10:40
-
-
Save tut-tuuut/4086324 to your computer and use it in GitHub Desktop.
Comparatif de querySelector, querySelectorAll et getElementById
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
var limit = 20000; | |
var i = 0; | |
console.time('queryselector'); | |
for (i = 0; i <= limit; i++) { | |
document.querySelector('#contentarea'); | |
} | |
console.timeEnd('queryselector'); // 165 ms | |
console.time('queryselectorall'); | |
for (i = 0; i <= limit; i++) { | |
document.querySelectorAll('#contentarea'); // 234 ms | |
} | |
console.timeEnd('queryselectorall'); | |
console.time('byid'); | |
for (i = 0; i <= limit; i++) { | |
document.getElementById('#contentarea'); | |
} | |
console.timeEnd('byid'); // 85 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment