Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JS Find vs FindIndex vs loop
(version: 1)
Comparing performance of:
Find vs FindIndex vs loop
Created:
2 months ago
by:
Guest
Go to the latest result
Script Preparation code:
var hasZero = []; var withoutZero = []; for (var i = 0; i < 10000; i++) { hasZero.push(Math.floor(Math.random() * 1000)); withoutZero.push(Math.floor(Math.random() * 1000) + 1) }
Tests:
Find
var tempResult = !!Math.round(Math.random()) ? hasZero.find(v => v === 0) : withoutZero.find(v => v === 0);
FindIndex
var tempResult = !!Math.round(Math.random()) ? hasZero.findIndex(v => v === 0) : withoutZero.findIndex(v => v === 0);
loop
var index = 0; var tempResult = null; if (!!Math.round(Math.random())) { for (let item of hasZero) { if (item == 0) { tempResult = index; break; } else index++; } } else { for (let item of withoutZero) { if (item == 0) { tempResult = index; break; } else index++; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Find
FindIndex
loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
loop
21K/s
FindIndex
18K/s
Find
18K/s
View exact numbers
Test name
Executions per second
✓
loop
20,983 Ops/sec
FindIndex
18,352 Ops/sec
Find
17,751 Ops/sec
Related benchmarks
JS Find vs FindIndex
Includes vs. IndexOf vs. Filter vs. Find vs. FindIndex vs. Some
Some vs. Filter vs. indexOf vs. Includes vs. Find vs. findIndex performance
Comments
Confirm delete:
Do you really want to delete benchmark?