3 ms·
Well, that seems more like an issue with the compiler then, cause avoiding overflows would not result in a 2x slow-down in C or C++.
by stabbles 8y ago
Well, that seems more like an issue with the compiler then, cause avoiding overflows would not result in a 2x slow-down in C or C++.
- steveklabnik 8y agoPossibly! Remember that the Rust language and C/C++ have different semantics with regards to overflow. It may be the programmer's "fault" for not writing the code with the equivalent semantics (you can make them have the same semantics, but it's not the default).
- stabbles 8y agoLooking at the Rust source [1] it seems there the `next()` call has some overhead, so it's probably not the compiler. I remember this was simple to implement in Julia [2] where you can iterate over the full range `for i = typemin(Int):typemax(Int) ... end` without overflow and without overhead. Same should be possible in Rust I think. [1] https://doc.rust-lang.org/src/core/iter/range.rs.html#340-353 https://doc.rust-lang.org/src/core/iter/range.rs.html#340-35... [2] https://github.com/JuliaLang/julia/blob/master/base/range.jl#L591-L598 https://github.com/JuliaLang/julia/blob/master/base/range.jl...