Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Move Multiple Elements to another - Winners
(version: 0)
Comparing performance of:
appendChild vs insertAdjacentElement
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<table class="old"> <tbody> <tr> <td class="old-td">old-td 1</td><td class="old-td">old-td 2</td><td class="old-td">old-td 3</td><td class="old-td">old-td 4</td><td class="old-td">old-td 5</td><td class="old-td">old-td 6</td><td class="old-td">old-td 7</td><td class="old-td">old-td 8</td><td class="old-td">old-td 9</td><td class="old-td">old-td 10</td> <td class="old-td">old-td 11</td><td class="old-td">old-td 12</td><td class="old-td">old-td 13</td><td class="old-td">old-td 14</td><td class="old-td">old-td 15</td><td class="old-td">old-td 16</td><td class="old-td">old-td 17</td><td class="old-td">old-td 18</td><td class="old-td">old-td 19</td><td class="old-td">old-td 20</td> <td class="old-td">old-td 21</td><td class="old-td">old-td 22</td><td class="old-td">old-td 23</td><td class="old-td">old-td 24</td><td class="old-td">old-td 25</td><td class="old-td">old-td 26</td><td class="old-td">old-td 27</td><td class="old-td">old-td 28</td><td class="old-td">old-td 29</td><td class="old-td">old-td 30</td> <td class="old-td">old-td 31</td><td class="old-td">old-td 32</td><td class="old-td">old-td 33</td><td class="old-td">old-td 34</td><td class="old-td">old-td 35</td><td class="old-td">old-td 36</td><td class="old-td">old-td 37</td><td class="old-td">old-td 38</td><td class="old-td">old-td 39</td><td class="old-td">old-td 40</td> <td class="old-td">old-td 41</td> <td class="old-td">old-td 42</td> <td class="old-td">old-td 43</td> <td class="old-td">old-td 44</td> <td class="old-td">old-td 45</td> <td class="old-td">old-td 46</td> <td class="old-td">old-td 47</td> <td class="old-td">old-td 48</td> <td class="old-td">old-td 49</td> <td class="old-td">old-td 50</td> </tr> </tbody> </table> <table class="new"> <tbody> <tr class="new-tr"> </tr> </tbody> </table>
Script Preparation code:
var table_td_arr = document.getElementsByClassName('old-td'), table_new_tr = document.getElementsByClassName('new-tr')[0];
Tests:
appendChild
for (var td_i = 0; td_i < table_td_arr.length; td_i++) { var table_td = table_td_arr[0]; table_new_tr.appendChild(table_td); }
insertAdjacentElement
for (var td_i = 0; td_i < table_td_arr.length; td_i++) { var table_td = table_td_arr[0]; table_new_tr.insertAdjacentElement('beforeend', table_td); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
appendChild
insertAdjacentElement
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 break down the benchmark and explain what's being tested, compared options, pros and cons, and other considerations. **Benchmark Overview** The benchmark measures the performance of two approaches for moving multiple elements from one table (`table_td_arr`) to another table (`table_new_tr`): `appendChild` and `insertAdjacentElement`. The test is run on a JavaScript code snippet that prepares the HTML tables and contains a loop that moves each element from `table_td_arr` to `table_new_tr`. **Options Compared** Two options are compared: 1. **appendChild**: This method adds a child node to the end of an element. 2. **insertAdjacentElement('beforeend')**: This method inserts a new element before the content of its parent container. **Pros and Cons** **appendChild:** Pros: * Simple and straightforward implementation * Well-supported by most browsers Cons: * May not be efficient for large datasets, as it involves creating multiple elements and appending them to the table row. * Can lead to increased DOM size and complexity, potentially affecting performance. **insertAdjacentElement('beforeend')**: Pros: * More efficient than `appendChild` since it only creates a single element and inserts it before the content of its parent container. * Reduces DOM size and complexity compared to `appendChild`. Cons: * May not be supported by older browsers or those with limited DOM support. * Can be slower due to the additional overhead of creating an element and inserting it into the DOM. **Other Considerations** * **DOM Size**: Both methods can impact DOM size, but `insertAdjacentElement('beforeend')` tends to reduce it more effectively. * **Browser Support**: `appendChild` is generally supported by all modern browsers, while `insertAdjacentElement('beforeend')` may have issues with older or less-supported browsers. **Library/Function** In the provided benchmark code, no specific library is used beyond basic JavaScript functionality. However, if you were to use a third-party library for DOM manipulation, it's essential to consider its impact on performance and browser support. **Special JS Feature/Syntax** None of the tested approaches utilize special JavaScript features or syntax that would require additional explanation. **Alternatives** If you're looking for alternative methods to move elements between tables, consider: 1. Using a library like jQuery, which provides efficient DOM manipulation methods. 2. Implementing your own custom solution using techniques like cloning and appending elements individually. 3. Leveraging modern browser features, such as `Element.insertAdjacentText()` or `Element.createDocumentFragment()`, for more efficient DOM updates. Keep in mind that the choice of approach ultimately depends on your specific use case, performance requirements, and desired level of complexity.
Related benchmarks:
innerHTML vs updateDOM
innerHTML vs updateDOM
innerHTML vs updateDOM
querySelectorAll vs getElementsByClassName performance test for demo
Javascript closest method benchmarks
Comments
Confirm delete:
Do you really want to delete benchmark?