Test name | Executions per second |
---|---|
Fetch vias Object.values() | 105617.7 Ops/sec |
Fetch via cached array | 9609163.0 Ops/sec |
class Basic {
obj = {};
add(k, v) {
this.obj[k] = v;
}
getValues() {
return Object.values(this.obj);
}
};
class Cached {
obj = {};
cache = [];
add(k, v) {
this.obj[k] = this.cache.length;
this.cache.push(v);
}
getValues() {
return this.cache;
}
};
basic = new Basic();
cached = new Cached();
for (let i = 0; i < 1000; i++) {
basic.add('a' + i, i);
cached.add('a' + i, i);
}
basic.getValues()
cached.getValues()