4 ms·
Funny enough, the iterator version is much faster in rust because the compiler can more easily optimize iterator chains than custom for loops: https://play.rus
by bschwindHN 2y ago
Funny enough, the iterator version is much faster in rust because the compiler can more easily optimize iterator chains than custom for loops:
https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=e4b11bda65cd43ba77678284c28e7f76 https://play.rust-lang.org/?version=stable&mode=release&edit...
(I'd recommend running it on your own machine as the rust playground limits memory and will likely kill this program)
Output from my machine:
$ cargo run --release
Finished `release` profile [optimized] target(s) in 0.05s
Running `target/release/iterator`
Process 1 returned 18270843109002848788 and took 64.58175ms
Process 2 returned 18270843109002848788 and took 308.969083ms