customEvents vs recursive parentNode

JavaScript performance comparison

Test case created by askbeka

Preparation code

<div id="test"></div>
      
<script>
Benchmark.prototype.setup = function() {
  window.test = document.getElementById('test');
  window.handler = (e) => {
    e.stopPropagation();
  };
  window.test.addEventListener('custom-event', window.handler);
  window.element = window.test;
  for (let i = 0; i < 1000; i++) {
    window.element = window.element.appendChild(document.createElement('div'));
  }

};

Benchmark.prototype.teardown = function() {
  window.test.removeEventListener('custom-event', window.handler);
  window.test.innerHtml = '';

};
</script>

Preparation code output

<div id="test"></div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
customEvent
window.element.dispatchEvent(new CustomEvent('custom-event'));
pending…
parentNode
let current = window.element.parentElement;
while (current.id !== 'test') {
  current = current.parentElement;
}
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.

0 Comments