I always thought that iterators in Rust are quite optimized and in most cases they outprform manual loops. But it seems that I wrong. At least if measuring in lines of resulting ASM code:
- First version - 1000 lines: https://godbolt.org/z/Wpjyfd
- Second version - replaced
a..b+1- 800 lines: https://godbolt.org/z/htXHMF
- Replace collect with mutable vector and
extend- 500 lines: https://godbolt.org/z/v-W7Iu
- Completely manual iterator - 500 lines: https://godbolt.org/z/-orLjK
I didn't benchmark it, although I think that manual loops are of the same performance as version #3.
What are good practices for that? I have chosen rust to write a clean code instead of manual loops but I'm returning to where I started, writing unnecessary stuff to make it performant.
Or there is a way to write in in a nice and clean way without paying for "zero" cost abstractions?