<ul id="list"></ul>
list.replaceChildren()
var oneThousandItems = []
var fragment = document.createDocumentFragment()
for (let i = 1; i <= 1000; i++) {
const li = document.createElement("li")
li.textContent = i
oneThousandItems.push(li)
fragment.append(li.cloneNode(true))
}
list.replaceChildren()
list.append(oneThousandItems)
list.replaceChildren()
list.append.call(list, oneThousandItems)
list.replaceChildren()
list.append(fragment)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
append(...array) | |
append.call(___, array) | |
append(DocumentFragment) |
Test name | Executions per second |
---|---|
append(...array) | 97.3 Ops/sec |
append.call(___, array) | 397.9 Ops/sec |
append(DocumentFragment) | 38106.9 Ops/sec |
Let's break down the provided benchmark and its test cases.
Benchmark Overview
The benchmark is designed to compare the performance of three different approaches for appending elements to an HTML list (ul element). The test aims to determine which approach is faster on mobile devices, specifically Android 10 with Chrome Mobile 103 browser.
Options Compared
There are three options being compared:
append
method.call
method to bind the append
method to a context (in this case, the list
element), and then calls it with the array as an argument.append
method.Pros and Cons
call
method and its usage in this context.Libraries Used
None of the test cases explicitly use a JavaScript library. However, the DocumentFragment
class is a built-in browser API for representing a subset of a document's content.
Special JS Features/Syntax
call
method is used in one of the test cases to bind the append
method to a context.Other Alternatives
If you're interested in exploring alternative approaches, consider these:
insertAdjacentHTML
: Instead of appending individual elements or using DocumentFragment
, you can use insertAdjacentHTML
method on the list element.Keep in mind that these alternatives may not be directly applicable to this specific benchmark, but they might be worth exploring in other scenarios where performance is crucial.