Object Iteration (v8)

Revision 8 of this benchmark created on


Setup

const entries = Array.from({length: 5000}, () => [String(Math.random()), Math.random()]);
const object = Object.fromEntries(entries);
const map = new Map(Object.entries(object));

Test runner

Ready to run.

Testing in
TestOps/sec
for entries
let sum = 0;
for (const [key, value] of Object.entries(object)) {
	sum += value;
}
ready
for keys (faster in chrome, same in FF)
let sum = 0;
for (const key of Object.keys(object)) {
	sum += object[key];
}
ready
Map Iteration entries (fastest in all browsers)
let sum = 0;
for (const [key, value] of map.entries()) {
	sum += value;
}
ready
Object creation fromEntries
Object.fromEntries(entries)
ready
Map creation fromEntries
new Map(entries)
ready
Object accessor
let sum = 0;
for (let i = 0; i < entries.length; i++) {
	sum += object[entries[i][0]] ?? 0
}
ready
map accessor
let sum = 0;
for (let i = 0; i < entries.length; i++) {
	sum += map.get(entries[i][0]) ?? 0
}
ready
object setter
let newObj = {};
for (let i = 0; i < entries.length; i++) {
	const entry = entries[i];
	newObj[entry[0]] = entry[1];
}
ready
map setter
let newMap = new Map();
for (let i = 0; i < entries.length; i++) {
	const entry = entries[i];
	newMap.set(entry[0], entry[1]);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.