Pub/Sub vs. jQuery custom events (v136)

Revision 136 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
(function($) {

  var o = $({});

  $.subscribe = function() {
    o.on.apply(o, arguments);
  };

  $.unsubscribe = function() {
    o.off.apply(o, arguments);
  };

  $.publish = function() {
    o.trigger.apply(o, arguments);
  };

}(jQuery));
</script>
<script>

  jQuery(function() {
  
   // subscribe our callback function to the custom event for jQuery
   jQuery(document).on("/some/topic", function (e, a, b, c) {
     console.log(a + b + c);
   });
  
   // subscribe our callback function to the message for PubSub
   jQuery.subscribe("/some/topic", function (e, a, b, c) {
     console.log(a + b + c);
    });
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery - trigger
$(document).trigger("/some/topic", [ "a", "b", "c" ]);
ready
Pub/Sub
jQuery.publish("/some/topic", [ "a", "b", "c" ]);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.