Test name | Executions per second |
---|---|
for..of Map.entries() | 5451.7 Ops/sec |
Map.foreach | 5630.8 Ops/sec |
for..of Map.entries() no destructuring | 6563.1 Ops/sec |
var array = Array.from({ length: 10000 }, () => {
const n = Math.floor(Math.random() * 100)
if (n > 26) {
return n
} else {
return String.fromCharCode('a'.charCodeAt(0) + n);
}
});
var obj = new Map();
for (let i = 0; i < array.length; i++) {
obj.set(i, array[i]);
}
for (const [key, val] of obj.entries()) {
const foo = val + 'a';
}
obj.forEach((val) => {
const foo = val + 'a';
})
for (const entry of obj.entries()) {
const key = entry[0];
const val = entry[1];
const foo = val + 'a';
}