虽然网上有中文翻译但是还是直接看英文有感觉。getElementByTagName 与 querySelectorAll在节点查询时候在效率上区别。
Conclusion
[color=blue]The real reason why getElementsByTagName() is faster than querySelectorAll() is because of the difference between live and static NodeList objects. Although I’m sure there are way to optimize this, doing no upfront work for a live NodeList will generally always be faster than doing all of the work to create a static NodeList. Determining which method to use is highly dependent on what you’re trying to do. If you’re just searching for elements by tag name and you don’t need a snapshot, then getElementsByTagName() should be used; if you do need a snapshot of results or you’re doing a more complex CSS query, then querySelectorAll() should be used.[/color]
参考:
[url]http://mzhou.me/?p=95119[/url]
[url]http://www.w3.org/TR/selectors-api/#queryselectorall[/url]
[url]http://www.nczonline.net/blog/2010/09/28/why-is-getelementsbytagname-faster-that-queryselectorall/[/url]
[url]http://jsperf.com/queryselectorall-vs-getelementsbytagname[/url]
Conclusion
[color=blue]The real reason why getElementsByTagName() is faster than querySelectorAll() is because of the difference between live and static NodeList objects. Although I’m sure there are way to optimize this, doing no upfront work for a live NodeList will generally always be faster than doing all of the work to create a static NodeList. Determining which method to use is highly dependent on what you’re trying to do. If you’re just searching for elements by tag name and you don’t need a snapshot, then getElementsByTagName() should be used; if you do need a snapshot of results or you’re doing a more complex CSS query, then querySelectorAll() should be used.[/color]
参考:
[url]http://mzhou.me/?p=95119[/url]
[url]http://www.w3.org/TR/selectors-api/#queryselectorall[/url]
[url]http://www.nczonline.net/blog/2010/09/28/why-is-getelementsbytagname-faster-that-queryselectorall/[/url]
[url]http://jsperf.com/queryselectorall-vs-getelementsbytagname[/url]