replace vs append

JavaScript performance comparison

Test case created

Preparation code

<div id="parent">
  <div id="child">111</div>
 </div>
<script>
Benchmark.prototype.setup = function() {
    var parent = document.querySelector('#parent');
     var child = document.querySelector('#child');
     var el = document.createElement('span');
     el.innerText = '555';
};
</script>

Preparation code output

111

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
append
parent.appendChild(el);
pending…
replace
parent.replaceChild(el, child)
pending…

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

Compare results of other browsers

0 comments

Add a comment