Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
object key vs indexof
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
loop lookup
2279662.2 Ops/sec
array indexed
3908394.0 Ops/sec
key lookup
7734552.0 Ops/sec
Script Preparation code:
var a = [{"id":7,"h":76},{"id":4,"h":34},{"id":9,"h":89}]; var b = []; for(var i=0;i<a.length;i++)b[i] = a[i].id; var c = []; for(var i=0;i<a.length;i++)c[a[i].id] = a[i];
Tests:
loop lookup
for(var i in a)if(i.id==9)return i;
array indexed
return a[b.indexOf(9)];
key lookup
return c[9];