Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object key access vs array index access
Tests the speed of accessing an item by object key vs array index.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser:
Firefox 146
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
Object key access
33384.6 Ops/sec
Array index access
32604.0 Ops/sec
Script Preparation code:
var items = Array.from( Array(1000), (item, index) => ({ key: index, value: index*10 }) ); var objContainer = new Object(); var arrContainer = new Array(items.length); // For a tenth of the number of items... for (let i = items.length/10; i >= 0; i--) { // Choose a random item const index = Math.floor(Math.random() * items.length); const item = items[index]; // Assign the item to the object and array containers objContainer[item.key] = item; arrContainer[item.key] = item; }
Tests:
Object key access
items.forEach((item) => objContainer[item.key]?.value)
Array index access
items.forEach((item) => arrContainer[item.key]?.value)