Performance of custom events and observer pattern in Node.js

I have a dilemma. I can choose between:

  • Emiting custom events and reacting on them,
  • Implementing observer pattern.

Events looks to be more simple, but what about performance? Do you know about any performance tests of these two techniques? It would be very helpful.

//BTW

Is it possible to add scope for events?

Both eventing and observer pattern share the same principal: trigger and react. Since Java do not have function pointers, therefore, we use an object to wrap around a function and notify when an event is triggered. This is observer pattern.

JavaScript supports function pointers. So we can remove the object "wrapper" and keep a list of event handlers at its very raw form: a function.

I don't know any perf tests about observer pattern or Node.JS event emitter. But memory-wise, keeping things small helps perf. Moreover, when a event is triggered, eventing don't require you to use a member accessor (i.e. the dot). This should save you some perf too.