Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array.indexof vs for
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
indexof
2602812.8 Ops/sec
for
15827.7 Ops/sec
indexof 2
3185848.0 Ops/sec
Script Preparation code:
var a=[]; a.length=1000; a.fill(0); a[500]=123; a[998]=234;
Tests:
indexof
a.slice(a.indexOf(123),a.indexOf(234));
for
let i=0; let st=0; while(i<a.length){ if(a[i]===123){ break; st=i; } i+=1; } let ed=0; while(i<a.length){ if(a[i]===234){ break; ed=i; } i+=1; } a.slice(st,ed);
indexof 2
const st=a.indexOf(123); a.slice(st,a.slice(st).indexOf(234));