Huge performance difference between iterators and for loops

"Nicer" is such a weird word to use here. Using iterators doesn't make it inherently nicer. The "uglier" implementation is stating "more directly" what the intent is. The issue with the iterator code is not only the functional overhead that the compiler has a more difficult time optimizing, but also that the matrix is being collected, rather than in-place modification like the first example.

In many cases, mutability will be faster than an immutable counter-part. In fact, this is why there are so many claims to Rust's speed as moving memory's ownership and modifying it is more efficient than cloning and modifying if taking ownership is a possibility.

/r/rust Thread