I was reading this article by Brandon Aaron here, about how jquery context may help. So i thought of doing a test of my own. So this is what I did.
Created
The #ID selector relies on the browser native document.getElementById. It's going to be fast no matter what.
Try a selector like div.class[attribute=value] with and without a context. For example*, you could select the "Related" question links to the right with this selector:
// Selects anchor elements with href's beginning with /questions/
$('a[href^=/questions/]')
But, it's faster to limit how many anchor elements the selector engine has to iterate over, evaluating that relatively expensive text matching:
$('a[href^=/questions/]', '.related')
* And ignoring the obviously easier .question-hyperlink class on those links, for the sake of discussion.