4 ms·
That’s just marketing. See: https://godbolt.org/z/q9zEj4 https://godbolt.org/z/q9zEj4 With exceptions turned on there’s a hidden call to _Unwind_Resume. Additi
by david2ndaccount 6y ago
That’s just marketing. See: https://godbolt.org/z/q9zEj4 https://godbolt.org/z/q9zEj4
With exceptions turned on there’s a hidden call to _Unwind_Resume. Additionally, the destructor has to be duplicated.
- microtherion 6y ago"you don't pay for it" doesn't mean that no code gets generated for exceptions in this case, but that no code gets executed unless an exception gets thrown, and your example does not disprove that.
- arcticbull 6y agoGenerated code has a cost in terms of size, of course, and in terms of performance via the addition of branching, branch mis-prediction penalty and decreased cache locality. This function invocation will also of course flush the pipeline and harm inlining. On a hot path this could be non-trivial.
- kllrnohj 6y agoWhile true it's also fewer branches than manual error handling via return values. So the only "fast" option is to just not handle errors at all. Which is a terrible recommendation, of course.
- alisonkisk 6y agoThat not the point, though. The point is that the cost is invisible with exceptions. For example, there could perhaps be an alternate version of C++ where every function is required to declare whether it could throw an exception (and a very smart compiler proves where it's possible), or that -fno-except flag is inverted so you have to opt in to exceptions.
- jcelerier 6y agoyou still have branches with noexcept, the difference is that they call std::terminate in case of stack unwinding.