Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
innerHTML 8930150.0 Ops/sec
removeChild 10675917.0 Ops/sec
remove 10654275.0 Ops/sec
innerText 7672295.5 Ops/sec
textContent 8612134.0 Ops/sec
HTML Preparation code:
AخA
 
1
<div id="container"></div>
Script Preparation code:
x
 
var node = document.getElementById('container');
for(var i = 0; i < 1000; i++) node.appendChild(document.createElement('div'));
Tests:
  • innerHTML

     
    var node = document.getElementById('container');
    node.innerHTML = '';
  • removeChild

     
    var node = document.getElementById('container');
    while(node.firstChild) node.removeChild(node.firstChild)
  • remove

     
    var node = document.getElementById('container');
    while(node.firstChild) node.firstChild.remove()
  • innerText

     
    var node = document.getElementById('container');
    node.innerText = '';
  • textContent

     
    var node = document.getElementById('container');
    node.textContent = '';