Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for-in vs object.keys.for-loop vs object.keys.forEach
Comparing performance for iterating over and object
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 142
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
5 months ago
Test name
Executions per second
for-in
4867.7 Ops/sec
Object.keys() -> for-loop
3888.4 Ops/sec
Object.keys() -> for-each
3089.2 Ops/sec
Script Preparation code:
const OBJ = { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1 }; const RUNS = 10_000;
Tests:
for-in
for (let i = 0; i < RUNS; i++) { const arr = []; for (const key in OBJ) { arr.push(key); } }
Object.keys() -> for-loop
for (let i = 0; i < RUNS; i++) { const arr = []; const keys = Object.keys(OBJ) for (let i = 0; i < keys.length; i++) { arr.push(keys[i]); }; }
Object.keys() -> for-each
for (let i = 0; i < RUNS; i++) { const arr = []; Object.keys(OBJ).forEach(key => arr.push(key)); }