Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Separate filter vs filter inside forEach
(version: 0)
Comparing performance of:
Just loop and simpleFilter inside vs Just loop and advancedFilter inside vs simpleFilter and loop vs advancedFilter and loop
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = []; for (let i = 0; i < 1000000; ++i) { arr[i] = Math.floor(Math.random() * 1000) } function simpleFilter(i) { return i % 2 == 0 } function advancedFilter(i) { return Math.round(i * 235.78) % 6 < 2 || Math.round(i * 8945.78) % 7 < 3 && Math.round(Math.sqrt(i)) * Math.round(Math.sqrt(i)) == i } var counters = { "t1a": 0, "t1b": 0, "t2a": 0, "t2b": 0, }
Tests:
Just loop and simpleFilter inside
arr.forEach(i => { if (i % 2 == 0) { ++counters["t1a"] } })
Just loop and advancedFilter inside
arr.forEach(n => { if (Math.round(i * 235.78) % 6 < 2 || Math.round(i * 8945.78) % 7 < 3 && Math.round(Math.sqrt(i)) * Math.round(Math.sqrt(i)) == i) { ++counters["t1b"] } })
simpleFilter and loop
arr.filter(i => simpleFilter(i)).forEach(_ => ++counters["t2a"])
advancedFilter and loop
arr.filter(i => advancedFilter(i)).forEach(_ => ++counters["t2b"])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Just loop and simpleFilter inside
Just loop and advancedFilter inside
simpleFilter and loop
advancedFilter and loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
slice vs filter2
slice vs filter more than 1000
Two lambdaless filters vs one lambded v2
slice vs filter 2
slice vs filter2
Comments
Confirm delete:
Do you really want to delete benchmark?