PostalJS vs. jQuery custom events vs AmplifyJs (v110)

Revision 110 of this benchmark created by RichardH on


Description

Testing the speeds of jQuery Custom Events with AmplifyJS and PostalJs

Preparation HTML

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://rawgithub.com/appendto/amplify/master/lib/amplify.min.js">
</script>
<script src="https://rawgithub.com/jashkenas/underscore/master/underscore-min.js"></script>
<script src="https://rawgithub.com/postaljs/postal.js/master/lib/postal.min.js"></script>
<script>
    var callback1 = function() {};
    var callback2 = function() {};
    var callback3 = function() {};
    var payload = {
        somekey: 'some value'
    };
    var body;

    // let's use jQuery.ready to make sure that the DOM is ready,
    // before trying to work with it
    jQuery(function() {
        // we'll use the body element to exchange messages for jQuery
        // if using deeper nested elements, jQuery will be slower, as custom events bubble
        body = $('body');

        // subscribe our callback1 function to the custom event for jQuery, only once
        body.bind('my-event', callback1);

        // subscribe our callback2 function to the message for PostalJs
        postal.channel().subscribe('my-event', callback2)

        // Subscribe to Amplify
        amplify.subscribe('my-event', callback3);
    });
</script>
</body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery - trigger
body.trigger('my-event', payload);
ready
AmplifyJs
amplify.publish('my-event', payload);
ready
PostalJs
postal.channel().publish("my-event", payload);
ready

Revisions

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