Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
For loop vs Index Of
save length of the array in the variable vs get it the loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser:
Chrome 119
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
for loop
1.3M/s
indexOf
27K/s
View exact numbers
Test name
Executions per second
✓
for loop
1,326,948 Ops/sec
indexOf
26,695 Ops/sec
Script Preparation code:
var arr = []; var count = 1000; for(var i = 0; i<count; i++) { arr.push(i); }
Tests:
for loop
function indexOfFor(obj, list) { var i; for (i = 0; i < list.length; i++) { if (list[i] === obj) { return i; } } return -1; }; indexOfFor(550, arr);
indexOf
arr.indexOf(550, arr);