Iterators and Streams in Rust and Haskell
> But look again: C is taking 87 nanoseconds, while Rust and Haskell both take about 175 microseconds. It turns out that GCC it able to optimize this into a downward-counting loop, which drastically improves the performance. We can do similar things in Rust and Haskell to get down to nanosecond-level performance, but that's not our goal today. I do have to say: well done GCC.<p>Downward-counting or not, it is simply impossible for GCC to generate code that executes all 1,000,000 iterations of the loop in 87ns.  That would be 87 femtoseconds per iteration, on average.<p>More likely, GCC figured out how to collapse the entire loop into a closed-form expression that is a function of the loop length.