Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36
Chrome 100
Windows
Desktop
2 years ago
Test name Executions per second
Remove firstChild 3185179.8 Ops/sec
RemoveChildren 2367089.0 Ops/sec
HTML Preparation code:
AخA
 
1
<div id='messages'></div>
Script Preparation code:
 
let list = document.getElementById("messages");
for(i=0; i<1000; i++) {
    list.innerHTML += "<span>Text</span>"
}
Tests:
  • Remove firstChild

     
    let list = document.getElementById("messages");
    while (list.firstChild) {
        list.removeChild(list.firstChild);
    }
  • RemoveChildren

     
    let list = document.getElementById("messages");
    list.replaceChildren();