Hello folks, I am trying to benchmark the sequence...
# stdlib
g
Hello folks, I am trying to benchmark the sequence API vs the stream API vs simple transformations. I am seeing some weird results that the stream API is always the slowest no matter the scenario (even for short circuit). Here is the repo: https://github.com/GeorgePap-719/StreamAllocationBenchmark
Is this expected? Maybe I am not using the jmh properly or smth
f
Hey! The
dataSet
list is always empty, because
buildList { for (number in 1..size) { .. }
uses list builder's size, not the benchmark parameter. The teardown method is called after each iteration, but the setup one is called only once per benchmark execution. As a result, the size parameter won't affect results anyway, as the list will be empty after the first iteration. Also, I'd suggest increasing the number of warmup iterations and using a more up-to-date version of JMH (1.37).
g
Hey Filipp, thanks for the help!
Run the benchmark again with your pointers, but still stream API is the slowest at short-circuit operations. Is this expected? From my understanding that is the strong point of the stream/sequence API where if we use take(k) the time com will be
k
and not
n
. 🤔
h
Did you look into this:
The teardown method is called after each iteration, but the setup one is called only once per benchmark execution. As a result, the size parameter won't affect results anyway, as the list will be empty after the first iteration.
Try instead
@Setup(Level.Iteration)
g
damn, my bad. My brain just skipped this. Thanks!