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
Which is the fastest way to create objects with hierarchical property lookup?
function Map(parent) {
this.__parent = parent;
}
Map.prototype = Object.create(null);
Map.prototype.get = function (key) {
var current = this;
do {
if (key in current) return current[key];
} while ((current = current.__parent) !== undefined);
};
function longProto() {
var current = Object.create(null);
current.i = 1;
var previous, counter;
for (var i = 0; i < 1000; i++) {
previous = current;
current = Object.create(previous);
counter = counter + current.i;
}
return counter;
}
function longMap() {
var current = new Map();
current.i = 1;
var previous, counter;
for (var i = 0; i < 1000; i++) {
previous = current;
current = new Map(previous);
counter = counter + current.get('i');
}
return counter;
}
function longCopy() {
var current = {};
current.i = 1;
var previous, counter;
for (var i = 0; i < 1000; i++) {
previous = current;
current = {i : previous.i};
counter = counter + current.i;
}
return counter;
}
var longProtoCount = 0;
var longCopyCount = 0;
var longMapCount = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
prototype chain |
| ready |
homegrown map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.