Using JMH to benchmark Java 8 Stream API ( parellel vs sequential) to sum up integer in list

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Dec 12 13:28:12 UTC 2014


Hi Ming Qin,

On 12.12.2014 08:33, Ming Qin wrote:
> Hi:  I wrote a blog (  http://wp.me/p1FzYe-9k ) to use JMH 1.3.3 to
> benchmark throughput of summing up integers hosted  in a List object
> through  different Java 8 API ( array, iterator , Stream sequential
> and Stream Parallel) .The result of my JMH benachmark codes indicated
> that Stream Parallel was the slowest one to sum up all integers .  I
> run this command to get results -java -jar target/benchmarks.jar
> JMHSample_01 -wi 5 -t 1 -i 5 -f 1 Before seeing the results, I
> anticipated that Steam Parallel approach should get better throughput
> number that Stream Sequential. I  doubted that the method of
> parallelSumIntegers() was not implemented correctly . Below are my
> codes. 

Three things:

 1. This is the list for JMH development, not general benchmark reviews.
Do you suspect a bug in JMH? I think not; therefore, your question
belongs on StackOverflow.

 2. The benchmark code is badly formatted [1], and it requires
additional steps to even read it, let alone build and run it. Why would
anyone abuse a simple JMH sample like that? Bootstrap a separate
benchmark project, set the source/target 1.8, and publish the entire
reproducer e.g. on GitHub.

 3. Stopping at the very first and obvious inconsistency while running
and publishing the benchmark results is an appalling practice,
contributing almost nothing to the world. The word "scrutinize" you
mention in your blog is key here. What you did does not count as
scrutinizing at all, it is just producing numbers, not figuring out
anything useful from them. Try to find the explanations yourself before
asking for help. Here are the examples of actual scrutinizing [2][3][4].

Thanks,
-Aleksey.

[1] http://mail.openjdk.java.net/pipermail/jmh-dev/2014-December/001516.html
[2] http://shipilev.net/blog/2014/java-scala-divided-we-fail/
[3] http://biboudis.github.io/clashofthelambdas/
[4]
http://stackoverflow.com/questions/25847397/erratic-performance-of-arrays-stream-map-sum
[5]
http://stackoverflow.com/questions/23756966/why-is-stringbuilderappendint-faster-in-java-7-than-in-java-8



More information about the jmh-dev mailing list