Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
tooltip js
(version: 0)
Comparing performance of:
from container vs from aria
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<ul> <li class="js-tooltip-container"> <button class="js-tooltip-opener" aria-controls="1">開く</button> <div class="js-tooltip" id="1"></div> </li> </ul>
Tests:
from container
const container = document.getElementsByClassName('js-tooltip-container')[0]; const opener = container.getElementsByClassName('js-tooltip-opener')[0]; const self = container.getElementsByClassName('js-tooltip')[0];
from aria
const self = document.getElementsByClassName('js-tooltip')[0]; const opener = document.querySelector(`[aria-controls="${self.id}"]`)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
from container
from aria
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):
Let's dive into the JavaScript microbenchmark on MeasureThat.net. **Benchmark Overview** The benchmark is designed to test the performance of two approaches for retrieving elements in a DOM tree: using `getElementsByClassName` from an element (Approach 1), and using `querySelector` with an attribute selector (Approach 2). The benchmark creates a simple HTML structure with a container, opener, and tooltip elements, and then measures how quickly these elements can be accessed using each approach. **Benchmark Definition** The benchmark definition is represented by the provided JSON: ```json { "Name": "tooltip js", "Description": null, "Script Preparation Code": null, "Html Preparation Code": "<ul>\r\n \t<li class=\"js-tooltip-container\">\r\n <button class=\"js-tooltip-opener\" aria-controls=\"1\">開く</button>\r\n <div class=\"js-tooltip\" id=\"1\"></div>\r\n \t</li>\r\n</ul>" } ``` This code defines a simple HTML structure with a container, opener, and tooltip elements. **Individual Test Cases** The benchmark consists of two test cases: 1. **"from container"`**: ```javascript const container = document.getElementsByClassName('js-tooltip-container')[0]; const opener = container.getElementsByClassName('js-tooltip-opener')[0]; const self = container.getElementsByClassName('js-tooltip')[0]; ``` This approach retrieves the `opener` element by traversing up from the `container` element, and then retrieves the `self` element using `getElementsByClassName`. This approach relies on the fact that the `aria-controls` attribute is set to match the `id` of the tooltip element. 2. **"from aria"`**: ```javascript const self = document.getElementsByClassName('js-tooltip')[0]; const opener = document.querySelector(`[aria-controls=\"${self.id}\"]`); ``` This approach retrieves the `opener` element by querying the DOM for an element with the specified attribute value, which is set to match the `id` of the tooltip element. **Library and Features** The benchmark uses the following JavaScript libraries: * None explicitly mentioned in the code. However, it does use some JavaScript features: * The `getElementsByClassName` method. * The `querySelector` method (specifically with an attribute selector). No special JS features or syntax are used beyond these standard methods. **Pros and Cons of Each Approach** 1. **"from container"`** * Pros: + More straightforward and efficient, as it only requires a single DOM traversal. * Cons: + May be slower due to the additional DOM traversal required to retrieve the `opener` element. 2. **"from aria"`** * Pros: + Can be faster, as it uses an attribute selector that can bypass some of the DOM traversal overhead. * Cons: + Requires more complex query logic, which may introduce additional parsing and processing overhead. **Other Alternatives** If you wanted to test different approaches for retrieving elements in a DOM tree, here are some alternatives: 1. Using `querySelectorAll` instead of `getElementsByClassName`. 2. Using `getElementById` or `getElementByTagName` instead of `getElementsByClassName`. 3. Using a CSS selector library like Sizzle or jQuery to query the DOM. 4. Using a more advanced query algorithm, such as the " CSSOM Query Algorithm" described in the W3C CSSOM specification. Keep in mind that these alternatives may have different performance characteristics and trade-offs, depending on the specific use case and requirements.
Related benchmarks:
Old Jquery, Vanilla event listen
New Jquery, Vanilla event listen
jQuery vs vanilla JS in selector class
Umbrella JS Lates
addEventListener() vs jQuery.on() with mouseEnter
Comments
Confirm delete:
Do you really want to delete benchmark?