Add and remove event listeners on window, document, body, or div

JavaScript performance comparison

Test case created

Preparation code

<div id="outerDiv">
    <div id="innerDiv">
    </div>
</div>
<script>
  var outerDiv = document.getElementById('outerDiv'),
      innerDiv = document.getElementById('innerDiv'),
      body = document.body;
 
  function func(event) {}
</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
window
window.addEventListener('mousemove', func, true);
window.removeEventListener('mousemove', func, true);
pending…
document
document.addEventListener('mousemove', func, true);
document.removeEventListener('mousemove', func, true);
pending…
body
body.addEventListener('mousemove', func, true);
body.removeEventListener('mousemove', func, true);
pending…
outerDiv
outerDiv.addEventListener('mousemove', func, true);
outerDiv.removeEventListener('mousemove', func, true);
pending…
innerDiv
innerDiv.addEventListener('mousemove', func, true);
innerDiv.removeEventListener('mousemove', func, true);
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:

0 comments

Add a comment