Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forinvsobjectkeys
(version: 0)
Comparing performance of:
forin vs objectkeys
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const fakeData = { item1: { isTexture: true }, item2: { isTexture: false }, item3: { isTexture: true }, item4: { isTexture: false }, item5: { isTexture: true } };
Tests:
forin
let textures = []; const startForIn = performance.now(); for (const key in fakeData) { const value = fakeData[key]; if (value && value.isTexture) { textures.push(value); } } const endForIn = performance.now(); console.log(`for-in loop execution time: ${endForIn - startForIn} ms`);
objectkeys
textures = []; // 重置数组 const startObjectKeys = performance.now(); const keys = Object.keys(fakeData); for (let i = 0; i < keys.length; i++) { const key = keys[i]; const value = fakeData[key]; if (value && value.isTexture) { textures.push(value); } } const endObjectKeys = performance.now(); console.log(`Object.keys loop execution time: ${endObjectKeys - startObjectKeys} ms`);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forin
objectkeys
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?