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
var obj = {foo: {bar: {baz: 123}}};
function find_forloop(o, path) {
var obj = o;
var parts = path.split(".");
for(var i=0;obj !== undefined && i<parts.length;i++) {
obj = obj[parts[i]];
}
return obj;
}
function find_using_reduce(obj, path) {
path.split('.').reduce(function (obj, key) {
return obj[key] || {};
}, obj);
}
var STOP = "stop";
function find_using_reduce_die_fast(obj, path) {
try {
path.split('.').reduce(function (obj, key) {
if (obj[key]) {
return obj[key];
}
throw STOP;
}, obj);
} catch (err) {
if (STOP === err) {
return;
}
// rethrow
throw err;
}
}
function find_using_while(obj, path) {
var parts = path.split('.');
while (obj && parts.length) {
obj = obj[parts.shift()];
}
return obj;
}
function find_InSteps(root, path) {
if (root && path) {
var steps = path.split('.'),
curStep = root,
stpI = 0, stpLen, step;
for (stpLen = steps.length; stpI < stpLen; stpI++)
/*for (stpI in steps)*/ {
step = steps[stpI];
if (curStep[step] !== undefined) {
curStep = curStep[step];
}
else {
return undefined;
}
}
return curStep;
}
return undefined;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
reduce |
| ready |
reduce + throw |
| ready |
while |
| ready |
evalPath |
| ready |
simple for loop |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.