Hi, IMO for less number of iterations/elements for loops are much
efficient, and when number gets higher both are performing with similar
efficiency. Advantage of parallel streams shows up when number of elements
increases and cost of each iteration increases.
Therefore, usage of streams/loops is highly dependent of the scenario and
can not suggest either without proper knowledge of the scenario, especially
for critical paths.

Regards,

On Thu, Apr 6, 2017 at 5:19 PM, Tharika Madurapperuma <[email protected]>
wrote:

> Hi Rajith,
>
>     IMO Java streams should not be used always as a practice. It is not a
> silver bullet. There can be issues in performance in some cases as you have
> pointed out.
>
>     One of the main advantage of using streams is when the logic of
> looping is quite complex and involves different operations on collections
> together, so that it can improve readability and understandability. But at
> the same time it can result in new and subtle bugs if we are not careful
> enough [1].
>
>      The performance aspect of streams vs loops depends on the type of the
> collection and the situation they deal with. This performance difference
> can sometimes be negligible. Hence we cannot completely go with one against
> another.
>
>      So IMHO we can consider using streams only when necessary based on
> our requirement and use loops where it deserves.
>
>
> [1] https://blog.jooq.org/2014/06/13/java-8-friday-10-subtle-
> mistakes-when-using-the-streams-api/
>
>
> Thanks,
> Tharika.
>
>
> On Thu, Mar 30, 2017 at 12:01 PM, Rajith Roshan <[email protected]> wrote:
>
>> Hi all,
>>
>> Most of our C5 development have used java8 streams api frequently more
>> than the for loops.
>> But there are some research have done to compare the performance of
>> streams api compared to for loops. They have shown that stream API is slow
>> compared to for loops in many scenarios (even for parallel streams). [1][2]
>>
>> Is there any proper guidance to use which one over the other or are we
>> using streams as a practice in C5 development
>>
>> [1] - https://blog.jooq.org/2015/12/08/3-reasons-why-you-shouldn
>> t-replace-your-for-loops-by-stream-foreach/
>> [2] - https://jaxenter.com/java-performance-tutorial-how-fast-ar
>> e-the-java-8-streams-118830.html
>>
>> Thanks!
>> Rajith
>>
>> --
>> Rajith Roshan
>> Software Engineer, WSO2 Inc.
>> Mobile: +94-72-642-8350 <%2B94-71-554-8430>
>>
>> _______________________________________________
>> Dev mailing list
>> [email protected]
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> *Tharika Madurapperuma*
> Software Engineer | WSO2, Inc.
>
> Email : [email protected]
> Mobile : +94777875624 <+94%2077%20787%205624>
> Web : http://wso2.com
>
> <http://wso2.com/signature>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Pumudu Ruhunage
Software Engineer | WSO2 Inc
M: +94 779 664493  | http://wso2.com
<https://wso2.com/signature>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to