3 ms·
Ok, so sometimes one is slower, sometimes faster. One interesting variable to look at is how much faster/slower exceptions are. Are we talking orders of magnitu
by delegate 10y ago
Ok, so sometimes one is slower, sometimes faster.
One interesting variable to look at is how much faster/slower exceptions are. Are we talking orders of magnitude ?
Last time I used exceptions was in the year 2000 (I kid you not).
I remember that after removing the exceptions, the socket code was several times faster.
I still don't use them mainly because of the unpredictability of the control flow.
- mikeash 10y agoThese days, exceptions are usually implemented so that code with exception-handling code is no slower than code without it, in the case where no exceptions are thrown, since that's the common case. These are called "zero cost exceptions." It's a rather misleading term, because the "zero cost" only applies when there are no exceptions thrown! You only get "zero cost" when you go through a try block without throwing. The tradeoff is that throwing an exception is pretty slow. Since all of the normal code is built as if no exceptions happen, throwing an exception has to go through and carefully unwind all the stuff currently in flight before it can start executing the catch. If your code very rarely throws, you'll be faster using exceptions. If it throws frequently, then you could easily end up losing an order of magnitude or three in performance.