News for hackers. Stuff that matters.
Re:Making the obvious code fast (2016) by twic on Wednesday April 17, 2019 @08:07AM (#19681783)
> Java 8 includes a very nice library called stream which provides higher order functions over collections in a lazy evaluated manner, similar to the F# Nessos streams library and Rust. Given that this is a lazy evaluated system, it is odd that there is such a performance difference between map then sum and a single reduction. The reduce function is compiling down to the equivalent of SSE vectorized C, but the map then sum is not even close. It turns out that the sum() method on DoubleStream "may be implemented using compensated summation or other technique to reduce the error bound in the numerical sum compared to a simple summation of double values." A nice feature, but not clearly communicated by the method name!

As i said recently [1], the Java way is to sacrifice a little performance to allow users to do silly things and still get the right answer.

[1] https://news.ycombinator.com/item?id=19644366

There are no comments on this comment yet.