Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array filter vs for + if
(version: 1)
Comparing performance of:
filter vs for + if
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const arraySize = 1_000_000; const numbers = Array.from({length: arraySize}, () => Math.floor(Math.random() * 100_000));
Tests:
filter
const evenWithFilter = numbers.filter((num) => num % 2 === 0);
for + if
const evenWithLoop = []; for (let i = 0; i < numbers.length; i++) { if (numbers[i] % 2 === 0) { evenWithLoop.push(numbers[i]); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
filter
for + if
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter
58.7 Ops/sec
for + if
68.7 Ops/sec
Related benchmarks:
Some vs. Filter
Some vs. Filter vs. indexOf
Some vs. Filter vs. indexOf
Some vs. Filter vs. indexOf
Some vs. Filter vs. indexOf 1
Some vs. Filter vs. indexOf vs every
Array.prototype.some() vs. Filter vs. Array.prototype.indexOf()
Array filter vs. for loop - with for in zz
filter vs push
Comments
Confirm delete:
Do you really want to delete benchmark?