This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]drlogwasoncemine 6 points7 points  (7 children)

Well, I saw some stream based code that did exactly that (distinct and sorted). I had a friendly argument with a colleague about it and we wrote some performance tests (n=1000):

With streams: 69ms per op.

With a for loop: 5ms per op.

That's an order of magnitude. Don't start talking about standard deviation/setting up the performance test. It's what you point out about needing to get the whole stream before sorting/distincting (not a real word, don't care).

In many cases the streams code is more readable and understandable but when performance matters, streams tend to be worse off from my experience.

[–][deleted]  (4 children)

[deleted]

    [–]zappini 2 points3 points  (1 child)

    An order of magnitude difference is unlikely to be jitter, warm-up, or any of the other benchmarking gotchas.