<div id="container"></div>
var node = document.getElementById('container');
for(var i = 0; i < 3; i++) node.appendChild(document.createElement('div'));
var node = document.getElementById('container');
node.innerHTML = '';
var node = document.getElementById('container');
while(node.firstChild) node.removeChild(node.firstChild)
var node = document.getElementById('container');
while(node.firstChild) node.firstChild.remove()
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
innerHTML | |
removeChild | |
remove |
Test name | Executions per second |
---|---|
innerHTML | 8661059.0 Ops/sec |
removeChild | 16083575.0 Ops/sec |
remove | 15748987.0 Ops/sec |
Let's dive into the benchmark and explain what's being tested.
Benchmark Overview
The test case compares three different approaches for removing child nodes from an HTML element: innerHTML
, removeChild
, and remove
. The benchmark is designed to measure the performance of these approaches in a scenario where multiple child nodes need to be removed.
What are we testing?
We're testing the execution time (in executions per second) of each approach on three different browsers (Chrome 99) and devices (Desktop). The test case consists of:
appendChild
.innerHTML
, removeChild
, or remove
.Options Compared
The benchmark compares the performance of three different approaches:
innerHTML
: Replacing the entire inner HTML of the element with an empty string.removeChild
: Removing each child node individually using node.removeChild
.remove
: Not a standard JavaScript method; the benchmark uses the remove()
method on node.firstChild
, which is not a recommended approach.Other Considerations
The benchmark does not account for the overhead of string manipulation, DOM updates, or other factors that might impact performance. Additionally, the test case only measures the execution time of each approach and does not consider other aspects like memory usage, garbage collection, or browser rendering effects.
Library Used (if any)
There is no explicit library used in this benchmark. However, it's worth noting that some browsers may use internal libraries or optimized implementations for DOM manipulation operations.
I hope this explanation helps!