5 ms·
> C, D, C++, rust, and nim should all have comparable performance; they all go through gcc|llvm, and all have the same optimizations. That's not necessarily tr
by Sean1708 7y ago
> C, D, C++, rust, and nim should all have comparable performance; they all go through gcc|llvm, and all have the same optimizations.
That's not necessarily true.
For example language semantics (essentially how much information the optimiser has) such as whether mutable pointers are allowed to alias (or even the existence of non-mutable pointers) can play a huge role in what optimisations can be applied in a given situation and even how effective certain optimisations are. Also default behaviours like D, rust, and nim doing bounds-check can change the practical speed (although not necessarily theoretical speed) of a language. And finally things like garbage collectors can make certain languages faster in some cases but slower in others (again there's a practical vs theoretical argument here, since you could get similar speed-ups using other techniques).
So no they don't necessarily have to have comparable performance, at least not in all situations.
- mhh__ 7y agoIt's a completely meaningless comparison in practice. D's contract mechanism (i.e. in/out, and invariant blocks) can provide very strong guarantees to the compiler (as a specified part of the language as opposed to a GCC pragma/builtin), which the LLVM D compiler definitely uses. All of the on by defaults that D has are usually there for a reason, i.e. floats are NaN initialized and bounds checking is on by default: These are very good idiot-proofing which can often be ignored unless profiling suggests there is a tangible issue.
- EvenThisAcronym 7y ago> D's contract mechanism [...] can provide very strong guarantees to the compiler... which the LLVM D compiler definitely uses. That's awesome. I didn't know LDC uses contracts like that. It'd be nice to have similar functionality across all D compilers.