DOMNodeInserted Performance

JavaScript performance comparison

Revision 4 of this test case created by Josh

Preparation code

<div id="parent"></div>
<div id="deafParent"></div>
<script>
Benchmark.prototype.setup = function() {
    var deafParent = document.getElementById('deafParent');
    var parent = document.getElementById('parent');
    var div = document.createElement("div");
   
    parent.addEventListener("DOMNodeInserted", function(e) {}, false);
   
};
</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
Append without event listener
deafParent.appendChild(div);
pending…
Append with event listener
parent.appendChild(div);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

Josh commented :

I don't think anyone would advocate adding thousands of event listeners to the page. Rather, add the listener to the parent element, and the performance difference is actually minimal.

Add a comment