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
Checking the performance of object instances vs object literals as mixins, with some Backbone.Marionette code
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<script>
var vent = _.extend({}, Backbone.Events);
var Marionette = {};
Marionette.BindTo = {
// Store the event binding in array so it can be unbound
// easily, at a later point in time.
bindTo: function (obj, eventName, callback, context) {
context = context || this;
obj.on(eventName, callback, context);
if (!this.bindings) { this.bindings = []; }
var binding = {
obj: obj,
eventName: eventName,
callback: callback,
context: context
}
this.bindings.push(binding);
return binding;
},
// Unbind from a single binding object. Binding objects are
// returned from the `bindTo` method call.
unbindFrom: function(binding){
binding.obj.off(binding.eventName, binding.callback, binding.context);
this.bindings = _.reject(this.bindings, function(bind){return bind === binding});
},
// Unbind all of the events that we have stored.
unbindAll: function () {
var that = this;
// The `unbindFrom` call removes elements from the array
// while it is being iterated, so clone it first.
var bindings = _.map(this.bindings, _.identity);
_.each(bindings, function (binding, index) {
that.unbindFrom(binding);
});
}
};
Marionette.EventBinder = function(){};
_.extend(Marionette.EventBinder.prototype, Marionette.BindTo);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Object Literal As Mixin |
| ready |
Object Literal As Prototype |
| ready |
Object Instances |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.