Sunday, November 9, 2014

Java 8 ‘Stream’ Performance Test


I have been recently testing out new features in JDK8. I think one of the most interesting feature which is available other than Lamda is Stream (java-doc). In summery it gives you a good way to do functional style of programming on Java collection, also it has something extra, it allows you to run operations in serial or parallel which in return allows developers to easily code parallel programming without needing to worry about complex programming logic.

I wanted to test the Stream performance for that I’m going to use a simple loop counter (source-code)

1) Normal (Serial)

2) Synchronized Object reference (Parallel)

3) Synchronised Array reference (Parallel)

4) Atomic (Serial)

5) Atomic (Parallel)

6) Stream (Serial)

7) Stream (Parallel)

8) If the Developer puts in the effort

Following is the results when running it from my laptop


As you can clearly see, a good developer can right a fast code, but its a game between Simplicity vs Performance.