Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for-in vs object.keys vs object.values for objects
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
for-in
3.4 Ops/sec
Object.keys
3.4 Ops/sec
Object.values
3.3 Ops/sec
Script Preparation code:
var obj = { 'a': { id: 'a', num: 1 }, 'b': { id: 'b', num: 1 }, 'c': { id: 'c', num: 1 }, 'd': { id: 'd', num: 1 }, 'e': { id: 'e', num: 1 }, 'f': { id: 'f', num: 1 }, 'g': { id: 'g', num: 1 }, };
Tests:
for-in
for (var i=10000; i > 0; i--) { for (var key in obj) { console.log(obj[key].id); } }
Object.keys
for (var i=10000; i > 0; i--) { Object.keys(obj).forEach(key => console.log(obj[key].id)); }
Object.values
for (var i=10000; i > 0; i--) { Object.values(obj).forEach(n => console.log(n.id)); }