Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object.keys for loop vs for in
(version: 1)
Comparing performance for iterating over and object
Comparing performance of:
for-in vs Object.keys() -> for-loop
Created:
8 months ago
by:
Guest
Go to the latest result
Script Preparation code:
const obj = { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1 };
Tests:
for-in
for (let i=10000; i > 0; i--) { const arr = []; for (const key in obj) { arr.push(key); } }
Object.keys() -> for-loop
for (let i=10000; i > 0; i--) { const keys = Object.keys(obj) for (let i=10000; i < keys.length; i--) { arr.push(keys[i]); }; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for-in
Object.keys() -> for-loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Object.keys() -> for-loop
9K/s
for-in
5K/s
View exact numbers
Test name
Executions per second
✓
Object.keys() -> for-loop
8,840 Ops/sec
for-in
5,173 Ops/sec
Related benchmarks
for-in vs object.keys map
for-in vs object.keys3
for-in vs object.keys normal
for-in vs object.keys.for-loop vs object.keys.forEach
Comments
Confirm delete:
Do you really want to delete benchmark?