Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: For vs for_each
The documentation of Iterator::for_each says:
In some cases
for_each
may also be faster than a loop, because it will use internal iteration on adapters likeChain
.
Now I am wondering what kind of cases are there and if there are simple examples of this? I feel like the advice in this documentation is a bit contradicting, i.e. it says for loops are generally more idiomatic but they might be slower. So if performance is important to me does this mean I should always use for_each
instead of for loops?
5 posts - 3 participants
🏷️ Rust_feed