Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
My Benchmark Name
(version: 0)
Comparing performance of:
getElementsByTagName vs querySelectorAll vs other vs all
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div> <div> <div></div> </div> <div></div> <div> <div> <div></div> </div> </div> <div></div> </div>
Script Preparation code:
var doc = document;
Tests:
getElementsByTagName
doc.getElementsByTagName('*');
querySelectorAll
doc.querySelectorAll(':not([touch-mode])');
other
doc.querySelectorAll('body *:not([touch-mode])');
all
doc.querySelectorAll('*');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
getElementsByTagName
querySelectorAll
other
all
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the test cases and options being compared. **Test Cases:** The provided benchmark has four individual test cases: 1. `getElementsByTagName`: Tests how fast the browser can retrieve all elements using `document.getElementsByTagName('*')`. 2. `querySelectorAll`: Tests how fast the browser can use CSS selectors to find elements using `doc.querySelectorAll(':not([touch-mode])')`. 3. `other`: This option seems out of place and doesn't make sense in this context. It might be a placeholder or an error. 4. `all`: Tests how fast the browser can retrieve all elements using `doc.querySelectorAll('*')`. **Options being compared:** The test cases are comparing different approaches to selecting elements: * `getElementsByTagName` uses a traditional, DOM-based method (i.e., retrieving all child nodes of the document). * `querySelectorAll` uses CSS selectors to select elements. * `all` uses the same approach as `getElementsByTagName`, but with a more efficient selector. **Pros and Cons:** 1. `getElementsByTagName`: Pros - widely supported, easy to use; Cons - less efficient than using CSS selectors. 2. `querySelectorAll`: Pros - more efficient than `getElementsByTagName`, can be faster for complex queries; Cons - requires support for CSS selectors in the browser, might not work in older browsers. 3. `all` (same as `getElementsByTagName`): Pros - same performance characteristics as `all`, but with a more specific selector; Cons - less intuitive name. **Library usage:** The test case uses the `document` object and its methods (`getElementsByTagName()`, `querySelectorAll()`). The `document` object is a part of the DOM (Document Object Model), which is a standard API for manipulating HTML documents in JavaScript. **Special JS features or syntax:** None mentioned, as all options are using standard JavaScript APIs and syntax. **Other alternatives:** If you wanted to test alternative approaches, you might consider adding more test cases, such as: * Using `querySelector` instead of `querySelectorAll` * Using `getElementById` instead of `getElementsByTagName` or `querySelectorAll` * Testing the performance of different CSS selectors (e.g., `*:not([touch-mode])`, `[data-foo]`) * Testing the performance of different DOM methods, such as `createElement` or `appendChild` These alternative approaches could provide more insight into the browser's performance and might be relevant for specific use cases. Keep in mind that the current test case is quite simple, focusing on basic element selection. More complex scenarios would require additional test cases to capture the full range of browser behavior.
Related benchmarks:
array.from vs array slice with querySelectorAll
Array.from vs Spread on querySelectorAll
Compare speed
querySelectorAll vs getElementsByTagName iteration test
querySelectorAll() vs getElementsByTagName() - with constant
Comments
Confirm delete:
Do you really want to delete benchmark?