<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>cletus</author><text>This is a good example of something that &lt;i&gt;sounds&lt;/i&gt; reasonable, even intuitive, but in practice just isn&amp;#x27;t &lt;i&gt;necessarily&lt;/i&gt; true.&lt;p&gt;Ever since the 486 we&amp;#x27;ve had zero-cost instructions, for example.&lt;p&gt;More pertinent to this, modern CPUs have multi-stage pipelines and branch prediction.&lt;p&gt;Third, just the possibility of throwing an exception has a cost as the program has to have the code to unwind the stack.&lt;p&gt;Last, humans have become increasingly bad at second-guessing compiler optimizations.&lt;p&gt;&amp;gt; This isn&amp;#x27;t rocket science, I&amp;#x27;m amazed that this isn&amp;#x27;t obvious.&lt;p&gt;Thing is, it kind of is rocket science. And it&amp;#x27;s not obvious. That&amp;#x27;s why you have to test.&lt;p&gt;Now you could take the position that exception lead to better designed code and might have other such benefits. Personally, I&amp;#x27;ve become more convinced over the years that exceptions are a false economy.</text><parent_chain><item><author>lallysingh</author><text>(quoting desc)
&lt;i&gt;sigh&lt;/i&gt;
(end quote)&lt;p&gt;Exceptions &lt;i&gt;make your code faster&lt;/i&gt; in the non-exceptional case.&lt;p&gt;See all those if-branches for error checks that don&amp;#x27;t exist in your code?  That branch-free code is going to run faster than your branchy code.  And the code&amp;#x27;s shorter, because it doesn&amp;#x27;t have the checks and handling intermixed, which makes it fit better into cache.&lt;p&gt;This isn&amp;#x27;t rocket science, I&amp;#x27;m amazed that this isn&amp;#x27;t obvious.</text></item></parent_chain></comment><story><title>Investigating the Performance Overhead of C++ Exceptions</title><url>https://pspdfkit.com/blog/2020/performance-overhead-of-exceptions-in-cpp/</url></story>
<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>abainbridge</author><text>Check out the godbolt link I posted under desc&amp;#x27;s thread. The answer isn&amp;#x27;t that obvious. Both approaches have a conditional. The compiler&amp;#x2F;linker marks the exception handling code as cold. In theory this could go in a section of the exe that the loader never pages into RAM. (I&amp;#x27;m getting out of my depth here).</text><parent_chain><item><author>lallysingh</author><text>(quoting desc)
&lt;i&gt;sigh&lt;/i&gt;
(end quote)&lt;p&gt;Exceptions &lt;i&gt;make your code faster&lt;/i&gt; in the non-exceptional case.&lt;p&gt;See all those if-branches for error checks that don&amp;#x27;t exist in your code?  That branch-free code is going to run faster than your branchy code.  And the code&amp;#x27;s shorter, because it doesn&amp;#x27;t have the checks and handling intermixed, which makes it fit better into cache.&lt;p&gt;This isn&amp;#x27;t rocket science, I&amp;#x27;m amazed that this isn&amp;#x27;t obvious.</text></item></parent_chain></comment><story><title>Investigating the Performance Overhead of C++ Exceptions</title><url>https://pspdfkit.com/blog/2020/performance-overhead-of-exceptions-in-cpp/</url></story>