Custom Event Firing
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
JQuery |
|
pending… |
AddEventListener |
|
pending… |
Callback |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments