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
What's the cost of a simple () => myObj.prop; getter?
var myObj = { a: 1 , b: 2, c: 3 };
// Need to combat lambda inlining.
var getters = [
() => myObj.a,
() => myObj.b,
() => myObj.c
];
var gettersWithComputation = [
() => myObj.a + 6,
() => myObj.b + 6,
() => myObj.c + 6
];
var myIndirectObj = {
a: { value: 1 },
b: { value: 2 },
c: { value: 3 }
};
var indirects = [
myIndirectObj.a,
myIndirectObj.b,
myIndirectObj.c
]
var oneThousandGetters = [];
var oneThousandGettersWithComputation = [];
var oneThousandIndirects = [];
for (var i = 0; i < 1000; i++) {
var index = Math.floor(Math.random(index));
oneThousandGetters.push(getters[index]);
oneThousandGettersWithComputation.push(gettersWithComputation[index]);
oneThousandIndirects.push(indirects[index]);
}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| Direct access | | ready |
| Simple getter | | ready |
| Getter with included computation | | ready |
| Readonly indirect object as getter | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.