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
Fastest way to dereference an object property path stored in a string.
function index(obj, i) {
return obj[i]
}
var obj = {
a: {
b: {
x: 0
}
}
};
function deref(obj, s) {
var i = 0;
s = s.split('.');
while (obj && i < s.length)
obj = obj[s[i++]];
return obj;
}
function derefrecursive(obj, s, i) {
if (i === undefined) i = 0;
if (i < s.length) return derefrecursive(obj[s[i]], s, i + 1);
return obj;
}
function deref2(obj, s) {
var i = 0;
var bits = s.split('.');
while (obj && i < bits.length)
obj = obj[bits[i++]];
return obj;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
split + reduce |
| ready |
eval |
| ready |
deref loop |
| ready |
deref recursive |
| ready |
deref loop 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.