Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for-in vs for loop
(version: 1)
Comparing performance of:
for-in vs Object.keys vs Object.values
Created:
one year ago
by:
Guest
Jump to the latest result
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 (let i=10000; i > 0; i--) { for (let key in obj) { console.log(obj[key].id); } }
Object.keys
const keys = Object.keys(obj) for (let i=10000; i > 0; i--) { for (let j=0; j < keys.length; j++){ console.log(obj[keys[j]].id) } }
Object.values
for (var i=10000; i > 0; i--) { Object.values(obj).forEach(n => console.log(n.id)); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for-in
Object.keys
Object.values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for-in
4.7 Ops/sec
Object.keys
4.8 Ops/sec
Object.values
4.7 Ops/sec
Related benchmarks:
for-in vs object.keys vs object.values for objects
for-in vs object.values for objects
for-in vs object.values vs object.entries for objects
Keys.length vs Values.length
forin vs obj.values().map
for-in vs object.keys vs object.values for objects vs arr
for-in vs object.keys vs object.values vs arr
for-in vs object.keys vs object.values for objects 2.0
Yet Another Object.keys vs Object.values
Comments
Confirm delete:
Do you really want to delete benchmark?