replaceChild vs. remove/appendChild

Benchmark created on


Preparation HTML

<div id="adiv">
  <p id="innerp">p elem</p>
  <span id="innerspan">span elem</span>
</div>
<script>
  function rChild() {
    var oldE = document.getElementById("innerspan");
    var newE = document.createElement("p");
    oldE.parentNode.replaceChild(newE, oldE);
  }
  function raChild() {
    var oldE = document.getElementById("innerspan");
    var newE = document.createElement("p");
    oldE.parentNode.removeChild(oldE);
    oldE.parentNode.appendChild(newE);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
replaceChild()
rChild();
ready
removeChild() / appendChild()
raChild();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.