Type | Native | Custom | Performance |
without listener | 2674.2 ms | 1545.4 ms | ~175% |
first listener | 2342.6 ms | 1264.5 ms | ~185% |
add a listener | 883.6 ms | 145.6 ms | ~605% |
All tests were done with 1'000'000 send actions. The second and third experiment result are only the additional cost. So we can observe that we gain a lot of time using our custom version. Additionally, the custom version gives you more flexibility for its purpose and throw away the useless things like bubbling, etc. We can set a channel in which we speak, give the number of arguments we want and select a event type. All actions are done in a static manner, so we don't have to bother with EventDispatcher, we only use "iEventListener". As you will see.
Example of structure for the EventCenter |
The third level is a list of all current listeners. For the moment, we use a simple ArrayList, but we could also implement a LinkedList to store the listeners and allow us to have constant time insert/delete. But to do that, we need to add some code in each listener. Because we use only an interface to have the biggest flexibility. Using a class like EventListener that contains the next/prev links needed by the linked list, we must use composition instead of simple inheritance.
All the code you need will come with the next tutorial...
No comments:
Post a Comment