Object.values vs for-in

Benchmark created on


Setup

let obj = {}, map = new Map(), set = new Set();
for(let i=0;i<1000;++i) {
	obj[i] = i;
	map.set(i,i);
	set.add(i);
}
let total = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
For-in
for(let k in obj) {
	total += obj[k];
}
ready
For of Object.values()
for(let v of Object.values(obj)) {
	total += v;
}
ready
Object.values().forEach()
Object.values(obj).forEach(v => total += v);
ready
Map.forEach()
map.forEach((k,v) => total += v);
ready
Map.values()
for(let v of map.values()) {
	total += v;
}
ready
Set.forEach()
set.forEach(v => total += v);
ready
Set.keys()
for(let v of set.keys()) {
	total += v;
}
ready

Revisions

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