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 <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 08:57:56 UTC