innerhtml vs removechild vs remove(my version)
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
Test name
Executions per second
innerHTML
1433984.0 Ops/sec
removeChild
3865580.0 Ops/sec
remove
3806469.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<div id="container"></div>
Script Preparation code:
var node = document.getElementById('container'); for(var i = 0; i < 1; 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()
Open this result on MeasureThat.net