removeChild VS replaceChlid

JavaScript performance comparison

Test case created by Remy_Juanes

Preparation code

<div id="here">
   <a>one</a>
   <a>two</a>
</div>
<script>
Benchmark.prototype.setup = function() {
    var div = document.getElementById("here");
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
RemoveChild + appendChild
var firstA = div.firstChild,
  oldA = div.removeChild(firstA);

div.appendChild(oldA);
pending…
ReplaceChild
var firstA = div.firstChild,
  lastA = div.lastChild;

div.replaceChild(firstA, lastA);
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