3 ms·
Someone found a single character change providing a 2x speedup: https://www.reddit.com/r/rust/comments/ab7hsi/comparing_pythagorean_triples_in_c_d_and_rust/ htt
by the_duke 8y ago
Someone found a single character change providing a 2x speedup: https://www.reddit.com/r/rust/comments/ab7hsi/comparing_pythagorean_triples_in_c_d_and_rust/ https://www.reddit.com/r/rust/comments/ab7hsi/comparing_pyth...
- orf 8y agoAhh yeah, using `..(z + 1)` makes it run faster than the C++ version.
- kzrdude 8y agoIt's code quality problems with the inclusive-end range iterator.
- bluejekyll 8y agoTo quote that reddit post, which I think has some good interesting details about why: “I believe the problem with ..= is that x..(y + 1) is not identical with x..=y. They are nearly equivalent on most values for x and y, except when y == i32::max(). At that point, x..=y should still be able to function, while x..(y + 1) is allowed to do nothing.”
- SlowRobotAhead 8y agoI don't know anything about Rust, but is it part of it's "safety" that it has operators to allow rollover of type max size and others that do not? As a C programmer, that sort of feels like cheating ;)
- steveklabnik 8y agoSafety means "memory safety". Integer overflow cannot cause memory unsafety directly, and so it's safe. (safe) Rust does not claim to make your code correct, it claims that it will not have undefined behavior. We do care about helping you make your code correct; it will check for overflow and panic at runtime in debug builds. But it's a secondary concern. Memory safety is hard enough!