Native Pubsub vs document pubsub

Benchmark created by Boaz Sender on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
  ;
  (function($) {
  
   $.bind = function(type, data, fn) {
  
    if (arguments.length === 2 || data === false) {
     fn = data;
     data = undefined;
    }
  
    jQuery.event.add(document, type, fn, data);
  
  
   };
  
   $.trigger = function(type, data) {
  
    jQuery.event.trigger(type, data);
  
   };
  
  })(jQuery);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
native
$.bind('customEvt', function(event) {
 console.log(event);
});

$.trigger('customEvt');
ready
jQuery
$(document).bind('customEvt', function(event) {
 console.log(event);
});

$(document).trigger('customEvt');
ready

Revisions

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

  • Revision 1: published by Boaz Sender on