Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
DOM structure: bottom up vs top down
(version: 0)
Comparing performance of:
Bottom up vs Top down
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Bottom up
const ul = document.createElement('ul'); for (const d of '123456') { const li = document.createElement('li'); li.textContent = d; ul.appendChild(li); } const container = document.createElement('div'); container.appendChild(ul);
Top down
const ul = document.createElement('div') .appendChild(document.createElement('ul')); for (const d of '123456') { const li = document.createElement('li'); li.textContent = d; ul.appendChild(li); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Bottom up
Top down
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
Browser/OS:
Firefox 132 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Bottom up
132957.1 Ops/sec
Top down
141914.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. **Benchmark Definition** The benchmark definition is quite simple, yet it highlights two different approaches to creating an unordered list (`ul`) and its child elements (`li`). 1. **Bottom-up approach**: This method starts by creating an empty `ul` element using `document.createElement('ul')`. Then, a loop iterates over the string '123456' to create each `li` element inside the `ul`. Finally, all `li` elements are appended to the `ul` using `appendChild`. 2. **Top-down approach**: This method starts by creating an empty `div` element and then appending a newly created `ul` element directly to it using `.appendChild(document.createElement('ul'))`. Then, another loop creates each `li` element inside the `ul` in the same way as before. **Comparison of options** The two approaches differ in their DOM tree creation: * **Bottom-up approach**: The DOM tree is built from scratch with each node created individually. * **Top-down approach**: A pre-existing `div` element serves as a container, and its child `ul` element is appended to it directly. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: **Bottom-up approach** Pros: * Easier to understand and maintain * More explicit control over DOM tree structure Cons: * May incur additional overhead due to repeated DOM creation * Less efficient if the same elements need to be created multiple times **Top-down approach** Pros: * Can lead to better performance by reusing existing nodes in the DOM tree * Simplifies certain types of rendering or layout calculations Cons: * Can make the code more complex and harder to understand * Adds an additional step to manage the pre-existing `div` container **Library usage** In this benchmark, no libraries are explicitly mentioned. However, if we consider modern JavaScript frameworks or libraries that manipulate the DOM, some might argue that a virtual DOM library like React or Preact could provide optimized implementations of these approaches. **Special JS features or syntax** None are mentioned in this specific benchmark definition.
Related benchmarks:
querySelector vs. getElementsByClassName nested dom
JQuery: find vs selector vs scoped selector - Class
querySelectorAll() vs getElementsByTagName()
querySelectorAll() vs getElementsByTagName() - with constant
querySelectorAll() vs getElementsByTagName() - with constant length
Comments
Confirm delete:
Do you really want to delete benchmark?