Java Streams vs For Loops: Performance Comparison #java #shorts #coding #airhacks

preview_player
Показать описание

Java used in this short: openjdk version "21" 2023-09-19 LTS

#airhacks
Рекомендации по теме
Комментарии
Автор

Thanks for actually trying that out. A fair comparison would have been using filter and generating a LinkedList though, as appending to a LinkedList is more costly in general and that's probably where the bulk of extra time comes from.

The parallelstream makes it very easy though to utilize multithreading, but I would challenge again that doing your own multithreaded divide-and-conquer with multiple for-loops might be faster again.

One thing that may also play a role is the lambda expression passed to filter() and maybe it's again faster if you would define a predicate function instead.

If you are still up to testing this. :)
I appreciate your effort.

Asto
Автор

What is difference between stream and parallelstream?

Hamza-dev.
join shbcf.ru