Pub/Sub implementations (v20)

Revision 20 of this benchmark created on


Description

Updated these to latest gist for jQuery 1.7

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  (function(jQuery) {
    var o = jQuery({});
    jQuery.each({
      "subscribe1": "bind",
      "unsubscribe1": "unbind",
      "publish1": "trigger"
    }, function(fn, api) {
      jQuery[fn] = function() {
        o[api].apply(o, arguments);
      };
    });
  })(jQuery);
</script>
<script>
  (function(jQuery) {
    var o = jQuery({});
    jQuery.each({
      "subscribe2": "on",
      "unsubscribe2": "off",
      "publish2": "trigger"
    }, function(fn, api) {
      jQuery[fn] = function() {
        o[api].apply(o, arguments);
      };
    });
  })(jQuery);
</script>
<script>
  (function($) {

    var o = $({});

    $.subscribe3 = function() {
      o.bind.apply(o, arguments);
    };

    $.unsubscribe3 = function() {
      o.unbind.apply(o, arguments);
    };

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

  })(jQuery);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery Events - bind/unbind
$.subscribe1('foo', function() {
  1 + 1;
});

$.publish1('foo', ['bar']);

$.unsubscribe1('foo');
ready
jQuery events - on/off
$.subscribe2('foo', function() {
  1 + 1;
});

$.publish2('foo', ['bar']);

$.unsubscribe2('foo');
ready
jQuery events - on/off (2)
$.subscribe3('foo', function() {
  1 + 1;
});

$.publish3('foo', ['bar']);

$.unsubscribe3('foo');
ready

Revisions

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