Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
More real
(version: 0)
Comparing performance of:
ID vs Closest vs ParentNode
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div class="container"> <section class="section1"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section2"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section3"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section4"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section5"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section6"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section7"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section8"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section9"> <div class="wrapperFake"> <div class="adSlotContainer"> <div class="slotFake"> <iframe class="iframeFake"></iframe> </div> </div> </div> </section> <section class="section10"> <div class="wrapper" id="wrapper"> <div class="adSlotContainer"> <div class="addtionalDiv"> <div class="addtionalDiv"> <div id="slot"> <iframe id="iframe"></iframe> </div> </div> </div> </div> </div> </section> </div>
Tests:
ID
let el1 = document.getElementById('iframe'); let el2 = document.getElementById('wrapper');
Closest
let el1 = document.getElementById('iframe'); let el2 = el1.closest('.wrapper');
ParentNode
let el1 = document.getElementById('iframe'); let el2 = el1.parentNode.parentNode.parentNode.parentNode;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
ID
Closest
ParentNode
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 break down the provided benchmark and its test cases. **Benchmark Definition** The benchmark definition is a JSON object that provides metadata about the benchmark. It includes: * `Name`: The name of the benchmark, which is "More real". * `Description`: An empty string, indicating no description for this benchmark. * `Script Preparation Code`: An empty string, meaning no script preparation code needs to be executed before running the benchmark. * `Html Preparation Code`: A HTML code snippet that generates a container with multiple sections, each containing an ad slot. The HTML is used to test various methods of accessing DOM elements. **Individual Test Cases** The benchmark consists of three individual test cases: 1. **ID** * `Benchmark Definition`: `let el1 = document.getElementById('iframe');\r\nlet el2 = document.getElementById('wrapper');` * Purpose: Tests the performance of using `document.getElementById` to access DOM elements. * Library: None (it's a basic JavaScript function) 2. **Closest** * `Benchmark Definition`: `let el1 = document.getElementById('iframe');\r\nlet el2 = el1.closest('.wrapper');` * Purpose: Tests the performance of using the `closest` method to access DOM elements. * Library: `Element.prototype.closest()` (a modern JavaScript function) 3. **ParentNode** * `Benchmark Definition`: `let el1 = document.getElementById('iframe');\r\nlet el2 = el1.parentNode.parentNode.parentNode.parentNode;` * Purpose: Tests the performance of using the `parentNode` property to access DOM elements. * Library: None (it's a basic JavaScript property) **Comparison and Analysis** The three test cases measure different methods of accessing DOM elements: * **ID**: Uses `document.getElementById`, which is a simple but potentially slow method, as it requires searching through all elements with the specified ID. * **Closest**: Uses `el1.closest('.wrapper')`, which is a more efficient method that traverses up the DOM tree until it finds an element with the specified class. However, this method may be slower than using `document.getElementById` if the closest matching element is not found quickly. * **ParentNode**: Uses multiple levels of `parentNode` properties to access the DOM element. This method can be slow and brittle, as it relies on the exact structure of the DOM. **Benchmark Results** The latest benchmark results show the performance metrics for each test case: | Test Name | ExecutionsPerSecond | | --- | --- | | ParentNode | 1040222.8125 | | Closest | 648668.3125 | | ID | 565955.625 | Based on these results, we can see that the `ParentNode` method is significantly faster than the other two methods, likely due to its ability to traverse up the DOM tree quickly. However, the difference in performance between `Closest` and `ID` is relatively small. **Conclusion** This benchmark provides a snapshot of how different methods of accessing DOM elements perform on various browsers and platforms. The results suggest that the `ParentNode` method is the fastest way to access DOM elements, but this may not always be the case in real-world scenarios where element structures are more complex or dynamic.
Related benchmarks:
Jquery fastest selector
Find vs select
Find vs select
getElementsByClassName, querySelector
getElementsByClassName, querySelector
Comments
Confirm delete:
Do you really want to delete benchmark?