jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
In this comparison I'm trying to focus on event inheritance feature present in PubSubJS and my implementation of the JQuery PubSub plugin.
In most PubSub implementations Subscribers and Publishers have a one to one relationship. This gives them a huge performance benefit, but can be a drawback when building complex decoupled applications as you have to wire every single event. In this comparison I'm looking at a pretty standard GUI like the one on google.com. We have a HEADER region, a tool region to the LEFT, a CONTENT region and a FOOTER. Each one of these regions are dependent on each other using PubSub to communicate. A MANAGER in each region is responsible for Loading/Unloading modules. A typical PubSub message for this application would look something like this:
"/APP/REGION/MODULE/EVENT"
Using a PubSub implementation that allows for inheritance allow us to create a subscriber for "/APP/REGION" that would listen to ALL events that occur within this region. Using the simpler implementations we would have to publish two events, one for the module and one for the region.
In this example each PubSub implementation has 4 subscribers. One for APP, REGION, MODULE and EVENT each. PubSubJS and JQuery Subscriber may invoke all four subscriber callbacks by a single publication to app/region/module/event where as the rest each has to publish 4 events.
More info
Compared:
<script src="https://raw.github.com/jrburke/requirejs/master/require.js" type="text/javascript">
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript">
</script>
<script src="https://raw.github.com/Sahadar/pubsub.js/master/pubsub.js" type="text/javascript">
</script>
<script src="https://raw.github.com/pmelander/Subtopic/master/jquery-subtopic.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/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.iter = 0
window.callback = function() {
iter++
};
window.payload = {
somekey: 'some value'
};
jQuery(function() {
jQuery(window).on('/app', callback);
jQuery(window).on('/app/region', callback);
jQuery(window).on('/app/region/module', callback);
jQuery(window).on('/app/region/module/event', callback);
// PubSubJS doesn't expose any globals when in AMD environment
require(['https://raw.github.com/mroderick/PubSubJS/master/src/pubsub.js'], function(PubSub){
// add PubSub to global scope, to not pay the cost in every execution of the tests
window.PubSub = PubSub;
PubSub.subscribe('app', callback);
PubSub.subscribe('app.region', callback);
PubSub.subscribe('app.region.module', callback);
PubSub.subscribe('app.region.module.event', callback);
});
jQuery.subscribe('/app', callback);
jQuery.subscribe('/app/region', callback);
jQuery.subscribe('/app/region/module', callback);
jQuery.subscribe('/app/region/module/event', callback);
Events.subscribe('/app', callback);
Events.subscribe('/app/region', callback);
Events.subscribe('/app/region/module', callback);
Events.subscribe('/app/region/module/event', callback);
amplify.subscribe('/app', callback);
amplify.subscribe('/app/region', callback);
amplify.subscribe('/app/region/module', callback);
amplify.subscribe('/app/region/module/event', callback);
pubsub.subscribe('/app', callback);
pubsub.subscribe('/app/region', callback);
pubsub.subscribe('/app/region/module', callback);
pubsub.subscribe('/app/region/module/event', callback);
Spine.bind('/app', callback);
Spine.bind('/app/region', callback);
Spine.bind('/app/region/module', callback);
Spine.bind('/app/region/module/event', callback);
Ply.core.listen('/app', callback);
Ply.core.listen('/app/region', callback);
Ply.core.listen('/app/region/module', callback);
Ply.core.listen('/app/region/module/event', callback);
require(["https://raw.github.com/jkroso/Observer/less-function-calls/dist/Observer.min.js", "https://raw.github.com/jkroso/Observer/Iterative-publish/dist/Observer.min.js"], function(Observer1, Observer2) {
window.recursive= new Observer1();
window.iterative= new Observer2();
recursive.subscribe('app', callback);
recursive.subscribe('app.region', callback);
recursive.subscribe('app.region.module', callback);
recursive.subscribe('app.region.module.event', callback);
iterative.subscribe('app', callback);
iterative.subscribe('app.region', callback);
iterative.subscribe('app.region.module', callback);
iterative.subscribe('app.region.module.event', callback);
});
});
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery Events |
| ready |
PubSubJS - async |
| ready |
PubSubJS - sync |
| ready |
Pure JS PubSub |
| ready |
Amplify Pub/Sub |
| ready |
Spine Events |
| ready |
Ply Notify/Listen |
| ready |
Recursive Observer |
| ready |
Iterative Observer |
| ready |
Subtopic for jQuery |
| ready |
pubsub.js |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.