title: Why don't throw() and noexcept have any overhead?
body: <p><code>throw()</code> was added in C++03 as an exception specifier, however it was deprecated in C++11 for the <code>noexcept</code> specifier.</p>
  
  <p>After profiling some code to find the speed using <code>throw()</code>, <code>noexcept</code> and just plain functions I found that all of them had roughly the same time for the function call. </p>
  
  <p>Results:</p>
  
  <pre><code>throw()       noexcept      plain old function
  11233 ms      11105 ms      11216 ms
  11195 ms      11122 ms      11150 ms
  11192 ms      11151 ms      11231 ms
  11214 ms      11218 ms      11228 ms
  
  compiled with MinGW using g++ -o test.exe inc.cpp no.cpp -std=c++11 -O3
  </code></pre>
  
  <p>Here is the code I used to profile:</p>
  
  <pre><code>int main() {
      unsigned long long iter = (unsigned long long)1 &lt;&lt; (unsigned long long)40;
      auto t1 = std::chrono::high_resolution_clock::now();
  
      for(unsigned long long i = 0; i &lt; iter; i++)
      {
  #ifdef THROW
          throw_func();
  #elif defined NOEXCEPT
          noexcept_func();
  #else
          std_func();
  #endif
       }
  
       auto t2 = std::chrono::high_resolution_clock::now();
  
       std::cout &lt;&lt; std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(t2 - t1).count() &lt;&lt; " ms" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The functions are defined as:</p>
  
  <pre><code>unsigned long long val = 1;
  
  struct exception {  };
  
  void throw_func(void) throw()
  {
      if (!val++)
         throw exception();
  }
  void noexcept_func(void) noexcept
  {
      if (!val++)
          throw exception();
  }
  void std_func(void)
  {
      if (!val++)
          throw exception();
  }
  </code></pre>
  
  <p>I was surprised by these results because I was under the impression that <code>throw()</code> and <code>noexcept</code> added some overhead to the function.</p>
  
  <p>Why doesn't <code>throw()</code> and <code>noexcept</code> add any overhead to the function call as compared to the regular function call?</p>