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
checky check
<script type="text/javascript">
var exists = function(prop, path, falseNull) {
if (typeof falseNull === "undefined" || falseNull === null) {
falseNull = false;
};
if ((typeof prop === "undefined" || prop === null)) {
return false;
} else if (falseNull && prop === false) {
return false;
}
if (typeof path !== "undefined") {
if (path.indexOf(",") >= 0 || typeof path !== "string") { return checkSet(); }
else { return checkDeep(); }
} else {
return !(typeof prop === "undefined" || prop === null || (falseNull && prop === false));
}
function checkDeep() {
var vals = path.split("."),
obj = prop;
for (var i = 0, len = vals.length; i < len; i++) {
if (typeof obj[vals[i]] === "undefined" || obj[vals[i]] === null) {
return false
} else if (falseNull && obj[vals[i]] === false) {
return false;
}
obj = obj[vals[i]];
}
return true;
}
function checkSet() {
var vals = (typeof path === "string") ? path.split(",") : [].concat(path),
obj = prop;
for (var i = 0, l = vals.length; i < l; i++) {
if (typeof obj[vals[i]] === "undefined" || obj[vals[i]] === null) {
return false;
} else if (falseNull && obj[vals[i]] === false) {
return false;
}
}
return true;
}
};
var exister = (function() {
var UNDEF = "undefined",
STRING = "string",
COMMA = ",",
DOT = ".";
/**
* Confirm an object path exists
* @param {object} obj object to test agains
* @param {string} path Dot delimited path
* @param {boolean} falseNull Should false be considered null
* @return {boolean} True if full path exist
*/
function checkDeep(obj, path, falseNull){
var vals = path.indexOf(DOT) != -1 ? path.split(DOT) : [path],
i = 0,
val = obj,
len = vals.length;
for (; i < len; i++) {
val = val[vals[i]];
if(nullOrUndef(val,falseNull)){
return false
}
}
return true;
}
/**
* Confirm a set of properties exist on an object
* @param {object} obj object to test agains
* @param {string} props Comma delimited set of properties
* @param {boolean} falseNull Should false be considered null
* @return {boolean} True if all properties exist
*/
function checkSet(obj,props,falseNull) {
var vals = (typeof props === STRING) ? (props.indexOf(COMMA) != -1 ? props.split(COMMA) : [props]): [].concat(props),
i = 0,
len = vals.length;
for (; i < len; i++) {
if(!checkDeep(obj,vals[i],falseNull)){
return false
}
}
return true;
}
/**
* Check if a object is undefined or null
* @param {mixed} thing Object to test
* @param {boolean}falseNull Should false be considered null
* @return {boolean} True if false or null
*/
function nullOrUndef(thing,falseNull){
return (typeof thing === UNDEF || thing === null || (falseNull && thing === false));
}
return function(prop, path, falseNull) {
falseNull = falseNull===true;
var nope = nullOrUndef(prop,falseNull);
if(nope){
return false
}
if (typeof path !== UNDEF){
return checkSet(prop, path, falseNull);
}
return !nope;
}
})();
var undef,
nullDef = null,
eObject = {},
eObjectProp = {property : 'yeah', path : { to : {thing : "thing"}}};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
old exists |
| ready |
new exists |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.