Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for-in vs object.keys (no hof in Object.keys, hasOwn check)
(version: 1)
Comparing performance of:
for-in vs Object.keys
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var obj = { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1 };
Tests:
for-in
for (var i=10000; i > 0; i--) { for (var key in obj) { if (!Object.hasOwn(obj, key)) continue; console.log(key); } }
Object.keys
for (var i=10000; i > 0; i--) { for (var key of Object.keys(obj)) console.log(key); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for-in
Object.keys
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for-in
1.9 Ops/sec
Object.keys
1.9 Ops/sec
Related benchmarks:
js for in vs object.keys
for-in with hasOwnProperty() vs object.keys
for-in vs Object.keys.forEach vs Object.keys with for loop
for-in with hasOwnProperty checking vs object.keys
for-in with hasOwnProperty guard vs object.keys
for-in vs for-of object.keys
for-in-hasOwnProperty vs object.keys
for-in-hasOwnProperty vs object.keys-direct
for-in own keys vs object.keys
Comments
Confirm delete:
Do you really want to delete benchmark?