Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object for...in vs for...index 2
(version: 1)
Comparing performance of:
forIn vs forIndex
Created:
9 months ago
by:
Registered User
Go to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
// 生成测试对象 const createTestObject = (size) => { const obj = {}; for (let i = 0; i < size; i++) { obj[`key${i}`] = i; } return obj; }; // 测试 for...in function testForIn(obj) { const start = performance.now(); for (const key in obj) { if (Object.hasOwn(obj, key)) { const value = obj[key]; } } return performance.now() - start; } // 测试 Object.keys + for function testObjectKeysFor(obj) { const start = performance.now(); const keys = Object.keys(obj); for (let i = 0; i < keys.length; i++) { const key = keys[i]; const value = obj[key]; } return performance.now() - start; } // 运行测试 const obj = createTestObject(1e3);
Tests:
forIn
testForIn(obj)
forIndex
testObjectKeysFor(obj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forIn
forIndex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Mobile Safari/537.36 EdgA/136.0.0.0
Browser/OS:
Chrome Mobile 136 on Android
View result in a separate tab
Embed
Embed Benchmark Result
forIndex
9K/s
forIn
7K/s
View exact numbers
Test name
Executions per second
✓
forIndex
8,807 Ops/sec
forIn
6,657 Ops/sec
Related benchmarks
for-in vs object.keys isEmpty
Object.entries vs ...
Object.entries vs ......
Object.keys vs for ... in
Object.keys vs for ... in (bigger object)
Object for...in vs for...index
Comments
Confirm delete:
Do you really want to delete benchmark?