A Comparison of JS Publish/Subscribe Approaches

JavaScript performance comparison

Revision 34 of this test case created by pmelande

Info

A Comparison of JS Publish/Subscribe Approaches

More info: publish/subscribe on Wikipedia.

Compared:

Preparation code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript">
</script>
<script src="https://raw.github.com/mroderick/PubSubJS/master/src/pubsub.js" type="text/javascript">
</script>
<script src="https://raw.github.com/lotaballs/bloody-jquery-plugins/master/pubsub.js" type="text/javascript">
</script>
<script src="https://raw.github.com/phiggins42/bloody-jquery-plugins/55e41df9bf08f42378bb08b93efcb28555b61aeb/pubsub.js" type="text/javascript">
</script>
<script src="https://raw.github.com/gist/1695338/736bcf94f9226d975fce3ad4f2bc08ccbf176bad/pubsub.js" type="text/javascript">
</script>
<script src="https://raw.github.com/appendto/amplify/master/core/amplify.core.js" type="text/javascript">
</script>
<script src="https://raw.github.com/maccman/spine/master/lib/spine.js" type="text/javascript">
</script>
<script src="https://raw.github.com/richardscarrott/ply/master/src/core.js" type="text/javascript">
</script>
<script type="text/javascript">
window.callback = function () {};
window.payload = {
  somekey: 'some value'
};

jQuery(function() {
  for (var i = 0; i < 10; i++) {
    jQuery(window).on('my-event-' + i, callback);
    PubSub.subscribe('my-event-' + i, callback);
    jQuery.subscribe('my-event-' + i, callback);
    Events.subscribe('my-event-' + i, callback);
    App.subscribe('my-event-' + i, callback);
    amplify.subscribe('my-event-' + i, callback);
    Spine.bind('my-event-' + i, callback);
    Ply.core.listen('my-event-' + i, callback);
  }
});
</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 Events
jQuery(window).trigger('my-event-9', payload);
 
pending…
PubSubJS
PubSub.publish('my-event-9', payload);
pending…
jQuery PubSub plugin
$.publish('my-event-9', [payload]);
pending…
Pure JS PubSub
Events.publish('my-event-9', [payload]);
pending…
Darcy Clarke
App.publish('my-event-9', [payload]);
pending…
Amplify Pub/Sub
amplify.publish('my-event-9', payload);
pending…
Spine Events
Spine.trigger('my-event-9', payload);
pending…
Ply Notify/Listen
Ply.core.notify('my-event-9', window, payload);
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