Custom Event Firing

JavaScript performance comparison

Test case created

Info

Compare speed of methods for firing custom events.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
  // For JQuery
  $(document).on("myEvent", function() { return true; });
  // For AddEventListener
  myEvent = new CustomEvent("myEvent");
  document.addEventListener("myEvent", function() { return true; });
  // For Callback - please note in reality you'd be setting a custom callback on a custom object - not DOM elements
  document.myCallback = function(data) { return true; };
</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
JQuery
$(document).trigger("myEvent", "test");
pending…
AddEventListener
myEvent.detail = "test";
document.dispatchEvent(myEvent);
pending…
Callback
document.myCallback("test");
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