Skip to content

Instantly share code, notes, and snippets.

@tut-tuuut
Created November 16, 2012 10:40
Show Gist options
  • Save tut-tuuut/4086324 to your computer and use it in GitHub Desktop.
Save tut-tuuut/4086324 to your computer and use it in GitHub Desktop.
Comparatif de querySelector, querySelectorAll et getElementById
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