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
An attempt at showing that PubSubJS is faster than using jQuery custom evens for publish/subscribe style messaging.
It's certainly not as rich in features, and I am happy with that.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://raw.github.com/mroderick/PubSubJS/master/src/pubsub.js"></script>
<script>
var callback1 = function() {};
var callback2 = function() {};
var callback3 = function() {};
var payload = {
somekey: 'some value'
};
var j;
var topics = {};
// 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
j = $({});
// subscribe our callback1 function to the custom event for jQuery, only once
j.on('my-event', callback1);
// subscribe our callback2 function to the message for PubSub
PubSub.subscribe('my-event', callback2);
// subscribe our callback3 function to the callbacks for jQuery.
topics["my-event"] = $.Callbacks();
topics["my-event"].add(callback3);
});
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery - trigger - custom event |
| ready |
PubSub - publish - asyncronous |
| ready |
PubSub - publish - syncronous |
| ready |
jQuery - fire - $.Callbacks |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.