.entries, for of, and .forEach (v2)

Revision 2 of this benchmark created on


Setup

const obj = {}
for(let i = 0; i< 10; i++){
	obj[i] = i + 2
}

Test runner

Ready to run.

Testing in
TestOps/sec
Object.entries().forEach() summation
let sum = 0
Object.entries(obj).forEach(([key,value]) => {
	if(key%2) sum += value
})
ready
for loop
let sum = 0
for (const key in obj) {
	if(key%2) sum += obj[key]
}
ready
Object.keys().forEach() summation
let sum = 0
Object.keys(obj).forEach((key) => {
	if(key%2) sum += obj[key]
})
ready

Revisions

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