- From: François REMY <francois.remy.dev@outlook.com>
- Date: Mon, 27 Apr 2015 12:27:33 +0200
- To: Glen Huang <curvedmark@gmail.com>, public-webapps <public-webapps@w3.org>
Received on Monday, 27 April 2015 10:28:02 UTC
Not sure this is a public-webapps issue but I'm pretty sure however that the reason is the return values of << getElement*By*(...) >> are cached by the browser which means that you end up not doing the work at all at some point in the loop, while you probably do it every single time for << querySelector >> which cannot return a cached result. From: curvedmark@gmail.com Date: Mon, 27 Apr 2015 16:57:23 +0800 To: public-webapps@w3.org Subject: Why is querySelector much slower? Intuitively, querySelector('.class') only needs to find the first matching node, whereas getElementsByClassName('.class')[0] needs to find all matching nodes and then return the first. The former should be a lot quicker than the latter. Why that's not the case? See http://jsperf.com/queryselectorall-vs-getelementsbytagname/119 for the test I know querySelectorAll is slow because of the static nature of returned NodeList, but this shouldn't be an issue for querySelector.
Received on Monday, 27 April 2015 10:28:02 UTC