Test name | Executions per second |
---|---|
Object Assignment | 10185250.0 Ops/sec |
Object Assignment + condition | 10208501.0 Ops/sec |
Set assignment | 10278274.0 Ops/sec |
Set assignment + condition | 10246101.0 Ops/sec |
Map assignment | 10304539.0 Ops/sec |
Map assignment + condition | 10249774.0 Ops/sec |
const myVar = 'test'
const mySet = new Set();
const myMap = new Map();
const myObj = {};
for(let i = 0; i < 100; i++) {
const newVar = `${myVar}${i}`;
mySet.add(newVar);
myMap.set(newVar, 0);
myObj[newVar] = 0;
}
const length = 100000000;
for (let i=0; i < length; i++) {
myObj.test = 1;
}
for (let i=0; i < length; i++) {
if (!myObj.test) myObj.test = 1;
}
for (let i=0; i < length; i++) {
mySet.add('test');
}
for (let i=0; i < length; i++) {
if (!mySet.has('test')) mySet.add('test');
}
for (let i=0; i < length; i++) {
myMap.set('test', 1);
}
for (let i=0; i < length; i++) {
if (!myMap.get('test')) myMap.set('test', 1);
}