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:
6 months ago
by:
Guest
Go 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:
6 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
filter
766/s
for loop slice
405/s
View exact numbers
Test name
Executions per second
✓
filter
766 Ops/sec
for loop slice
405 Ops/sec
Related benchmarks
filter vs splice index
splice VS filter: filtering big list of elements
filter vs splice and indexOf
Array remove
Comments
Confirm delete:
Do you really want to delete benchmark?