5 ms·
> I estimate it wouldn't be even two times slower in most of the use cases. In his "We Need Hardware Traps for Integer Overflow"[0], Regher quotes 5% to 100% o
by masklinn 12y ago
> I estimate it wouldn't be even two times slower in most of the use cases.
In his "We Need Hardware Traps for Integer Overflow"[0], Regher quotes 5% to 100% overhead for languages such as JS or Racket, and that a "highly tuned" checker would likely be in the 5% range. Playing with arithmetics-heavy programs and Rust's checked_* (which are backed by LLVM's overflow intrinsics[1]) I got anywhere from 5 to 40% performance loss IIRC.
That's not a lot, but at the same time when you're competing with languages specifically not paying those 5%, a 5% hit on all computations is not going to get you much love.
Which is why Rust currently lets you do that (via num::Checked* and num::Saturating) but uses overflowing default semantics.
[0] http://blog.regehr.org/archives/1154 http://blog.regehr.org/archives/1154
[1] http://llvm.org/docs/LangRef.html#arithmetic-with-overflow-intrinsics http://llvm.org/docs/LangRef.html#arithmetic-with-overflow-i...
- masklinn 12y agoOTOH I must note that Swift, on the other hand, has opted to error on overflow and have a second set of overflowing operators: https://developer.apple.com/library/mac/documentation/swift/conceptual/swift_programming_language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-XID_73 https://developer.apple.com/library/mac/documentation/swift/...
- acqq 12y agoAnd that's the best approach I can imagine: programmer should be able to control if he wants 5% penalty or speed. It's a win-win.