HTML Preparation code:
x
 
1
<div id='test'>
2
    <p>Lorem ipsum dolor sit amet</p>
3
    <p>Lorem ipsum dolor sit amet</p>
4
    <p>Lorem ipsum dolor sit amet</p>
5
    <ul>
6
        <li>Lorem ipsum dolor sit amet</li>
7
        <li>Lorem ipsum dolor sit amet</li>
8
        <li>Lorem ipsum dolor sit amet</li>
9
        <li>Lorem ipsum dolor sit amet</li>
10
    </ul>
11
    <p>Lorem ipsum dolor sit amet</p>
12
    <p>Lorem ipsum dolor sit amet</p>
13
    <p>Lorem ipsum dolor sit amet</p>
14
    <div>
15
        <p>Lorem ipsum dolor sit amet</p>
16
        <p>Lorem ipsum dolor sit amet</p>
17
        <p>Lorem ipsum dolor sit amet</p>
18
    </div>
19
    <p>Lorem ipsum dolor sit amet</p>
20
    <p>Lorem ipsum dolor sit amet</p>
21
    <p>Lorem ipsum dolor sit amet</p>
22
    <ul>
23
        <li>Lorem ipsum dolor sit amet</li>
24
        <li>Lorem ipsum dolor sit amet</li>
25
        <li>Lorem ipsum dolor sit amet</li>
26
        <li>Lorem ipsum dolor sit amet</li>
27
    </ul>
28
    <p>Lorem ipsum dolor sit amet</p>
29
    <p>Lorem ipsum dolor sit amet</p>
30
    <p>Lorem ipsum dolor sit amet</p>
31
    <div>
32
        <p>Lorem ipsum dolor sit amet</p>
33
        <p>Lorem ipsum dolor sit amet</p>
34
        <p>Lorem ipsum dolor sit amet</p>
35
    </div>
36
</div>
37
38
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
Script Preparation code:
 
function removeAllNodeChildren(node) {
    while (node.hasChildNodes()) {
        node.removeChild(node.lastChild);
    }
    return node;
}
function purge(node) {
    if (node.hasChildNodes()) {
        node.innerHTML = '';
    }
    return node;
}
Tests:
  • removeChild

     
    removeAllNodeChildren(document.getElementById('test').cloneNode(true));
  • innerHTML

     
    purge(document.getElementById('test').cloneNode(true));
  • jQuery

     
    $(document.getElementById('test').cloneNode(true)).html('')
  • replaceChildren

     
    document.getElementById('test').cloneNode(true).replaceChildren();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    removeChild
    innerHTML
    jQuery
    replaceChildren

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Chrome 120 on Windows
View result in a separate tab
Test name Executions per second
removeChild 13232.0 Ops/sec
innerHTML 20030.9 Ops/sec
jQuery 14821.2 Ops/sec
replaceChildren 13927.2 Ops/sec