Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter vs for loop splice
(version: 1)
comparing array filter vs repeated splicing
Comparing performance of:
filter vs for loop slice
Created:
3 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
let data = Array(300).fill(2); data.fill(-3, 150, 200); const size = data.length;
Tests:
filter
for(let tick = 0; tick < 1000; tick++) { data = data.filter(element => element > 0); }
for loop slice
for(let tick = 0; tick < 1000; tick++) { for (let i = size - 1; i >= 0; --i) { if (data[i] <= 0) { data.splice(i, 1); } } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
filter
for loop slice
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter
765.9 Ops/sec
for loop slice
405.5 Ops/sec
Related benchmarks:
Slice, splice, and filter
filter vs splice index
cutArray
filter vs splice 2
splice VS filter: filtering big list of elements
Custom splice based array filter
add many elements to beginning of array: unshift vs splice
filter vs splice and indexOf
Array remove
Comments
Confirm delete:
Do you really want to delete benchmark?