Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
eq vs object.keys vs object.values for objects
(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 }, }; var arr = [ { id: 'a', num: 1 }, { id: 'b', num: 1 }, { id: 'c', num: 1 }, { id: 'd', num: 1 }, { id: 'e', num: 1 }, { id: 'f', num: 1 }, { id: 'g', num: 1 }, ];
Tests:
for-in
for (var i=10000; i > 0; i--) { arr.forEach(i => { console.log(i.id === 'e') }) }
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)); }
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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for-in
10.6 Ops/sec
Object.keys
10.3 Ops/sec
Object.values
10.4 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
for-in vs object.keys vs object.values for objects v2
for-in vs object.keys vs object.values for objects vs arr
for-in vs object.keys vs object.values for objects - output object values
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?