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
Testing different method of implementing custom events
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js">
</script>
<script>
//Copyright (c) 2010 Nicholas C. Zakas. All rights reserved.
//MIT License
function EventTarget() {
this._listeners = {};
}
EventTarget.prototype = {
constructor: EventTarget,
addListener: function(type, listener) {
if (typeof this._listeners[type] == "undefined") {
this._listeners[type] = [];
}
this._listeners[type].push(listener);
},
fire: function(event) {
if (this._listeners[event.type] instanceof Array) {
var listeners = Object.extend({}, this._listeners[event.type]);
for (var i = 0, len = listeners.length; i < len; i++) {
listeners[i].call(this, event);
}
}
},
removeListener: function(type, listener) {
if (this._listeners[type] instanceof Array) {
var listeners = this._listeners[type];
for (var i = 0, len = listeners.length; i < len; i++) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
break;
}
}
}
}
};
var target = new EventTarget();
var c = 0;
function handleEvent(event) {
c += event.num;
};
target.addListener("foo", handleEvent);
Event.observe(document, "dom:foo", handleEvent);
document.addEventListener('foo', handleEvent);
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Array method |
| ready |
Event.observe |
| ready |
Test addEventListener |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.