Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Object for...in vs for...index 2【no hasOwn】
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 15; Mobile; rv:148.0) Gecko/148.0 Firefox/148.0
Browser:
Firefox Mobile 148
Operating system:
Android
Device Platform:
Mobile
Date tested:
6 months ago
Benchmark engine:
Benchmark.js
forIn
3.9M/s
forIndex
3.8M/s
View exact numbers
Test name
Executions per second
✓
forIn
3,905,115 Ops/sec
forIndex
3,758,336 Ops/sec
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) { 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(10);
Tests:
forIn
testForIn(obj)
forIndex
testObjectKeysFor(obj)