coffee vs js events
JavaScript performance comparison
Preparation code
<script type="text/javascript">
function EventBinder () {
this.events = {};
};
EventBinder.prototype.bind = function bind (on, fn, context) {
if (!this.events[on]) {
this.events[on] = [];
}
context = context || this;
this.events[on].push({handler : fn, context : context});
};
EventBinder.prototype.trigger = function trigger (evt) {
var args = Array.prototype.slice.call(arguments).slice(1);
if (this.events[evt]) {
this.events[evt].forEach(function (caller) {
caller.handler.apply(caller.context, args);
});
}
};
function CoffeeEvent () {
var events,
__slice = Array.prototype.slice;
events = {
events: {},
bind: function(topic, handler, context) {
var _base;
if (context == null) context = this;
return ((_base = this.events)[topic] || (_base[topic] = [])).push({
handler: handler,
context: context
});
},
trigger: function() {
var args, event, topic, _i, _len, _ref, _results;
topic = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
if (this.events[topic] != null) {
_ref = this.events[topic];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
event = _ref[_i];
_results.push(event.handler.apply(event.context, args));
}
return _results;
}
}
};
return events;
};
</script>
<script>
Benchmark.prototype.setup = function() {
var e = new EventBinder();
var c = CoffeeEvent();
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
JavaScript |
|
pending… |
CoffeeScript |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Joshua Kehn
0 comments