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
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
<script>
(function(){
if(Object.defineProperties) {
var set = function (obj, prop, val) {
if(val !== undefined) {
Object.defineProperty(obj, prop, {
value : val
});
}
return val;
},
special = {
pageX : function (original) {
var eventDoc = this.target.ownerDocument || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
return original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
},
pageY : function (original) {
var eventDoc = this.target.ownerDocument || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
return original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
},
relatedTarget : function (original) {
if(!original) {
return;
}
return original.fromElement === this.target ? original.toElement : original.fromElement;
},
metaKey : function (originalEvent) {
return originalEvent.ctrlKey;
},
which : function (original) {
return original.charCode != null ? original.charCode : original.keyCode;
}
},
oldEvent = jQuery.Event;
jQuery.each(jQuery.event.keyHooks.props.concat(jQuery.event.mouseHooks.props).concat(jQuery.event.props), function (i, prop) {
if (prop !== "target") {
(function () {
Object.defineProperty(jQuery.Event.prototype, prop, {
get : function () {
// get the original value, undefined when there is no original event
var originalValue = this.originalEvent && this.originalEvent[prop];
// overwrite getter lookup
return this['_' + prop] !== undefined ? this['_' + prop] : set(this, prop,
// if we have a special function and no value
special[prop] && originalValue === undefined ?
// call the special function
special[prop].call(this, this.originalEvent) :
// use the original value
originalValue)
},
set : function (newValue) {
this['_' + prop] = newValue;
}
});
})();
}
});
jQuery.event.fastFix = function (event) {
if (event[ jQuery.expando ]) {
return event;
}
// Create a jQuery event with at minimum a target and type set
var originalEvent = event,
event = jQuery.Event(originalEvent);
event.target = originalEvent.target;
// Fix target property, if necessary (#1925, IE 6/7/8 & Safari2)
if (!event.target) {
event.target = originalEvent.srcElement || document;
}
// Target should not be a text node (#504, Safari)
if (event.target.nodeType === 3) {
event.target = event.target.parentNode;
}
return event;
}
} else {
jQuery.event.fastFix = jQuery.event.fix;
}
})();
var makeClick = function(){
var event;
try {
event = document.createEvent('MouseEvents');
event.initMouseEvent("click", true, true, null, null, 100, 100, 100, 100, false, false, false, false, 0, null);
} catch (e) {
event = document.createEventObject();
} finally {
if(event.initEvent) {
event.initEvent("click", true, true);
}
}
return event;
}
</script>
var clickEvent = makeClick();
Ready to run.
Test | Ops/sec | |
---|---|---|
existing fix |
| ready |
fast fix |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.