Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Some vs. Filter vs. indexOf 1
(version: 0)
Comparing performance of:
Array.some vs Array.filter vs Array.indexOf vs Array.for
Created:
5 years ago
by:
Guest
Jump 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:
Array.some
var tempResult = !!Math.round(Math.random()) ? hasZero.some(v => v === 0) : withoutZero.some(v => v === 0);
Array.filter
var tempResult = !!Math.round(Math.random()) ? hasZero.filter(v => v === 0) : withoutZero.filter(v => v === 0);
Array.indexOf
var tempResult = !!Math.round(Math.random()) ? hasZero.indexOf(0) > -1 : withoutZero.indexOf(0) > -1;
Array.for
var data = !!Math.round(Math.random()) ? hasZero : withoutZero; var action = (a) => a === 0; var length = data.length; var tempResult = false; for (let i = 0; i < length; i++) { const tempResult = action(data[i], i); if (tempResult === true) { break; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array.some
Array.filter
Array.indexOf
Array.for
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.some
98691.1 Ops/sec
Array.filter
34638.3 Ops/sec
Array.indexOf
1280935.1 Ops/sec
Array.for
213154.8 Ops/sec
Related benchmarks:
Some vs. Filter vs. indexOf vs every
Some vs. Filter vs. indexOf v includes
Some vs. Filter vs. indexOf vs Includes
Array.prototype.some() vs. Filter vs. Array.prototype.indexOf()
Comments
Confirm delete:
Do you really want to delete benchmark?