title: How does the C++ compiler evaluate recursive constexpr functions so quickly?
body: <p>I've been learning about C++ <code>constexpr</code> functions, and I implemented a <code>constexpr</code> recursive function to find the nth fibonacci number.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cmath&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  
  constexpr long long fibonacci(int num) {
      if (num &lt;= 2) return 1;
      return fibonacci(num - 1) + fibonacci(num - 2);
  }
  
  int main() {
      auto start = clock();
      long long num = fibonacci(70);
      auto duration = (clock() - start) / (CLOCKS_PER_SEC / 1000.);
      std::cout &lt;&lt; num &lt;&lt; &quot;\n&quot; &lt;&lt; duration &lt;&lt; std::endl;
  }
  </code></pre>
  <p>If I remove the <code>constexpr</code> identifier from the <code>fibonacci()</code> function, then <code>fibonacci(70)</code> takes a <em>very long</em> time to evaluate (more than 5 minutes). When I keep it as-is, however, the program still compiles within 3 seconds and prints out the correct result in less than <code>0.1</code> milliseconds.</p>
  <p>I've learned that <code>constexpr</code> functions are evaluated <strong>at compile time</strong>, so this would mean that <code>fibonacci(70)</code> is calculated by the compiler in less than 3 seconds! However, it doesn't seem quite right that the C++ compiler would have such better calculation performance than C++ code.</p>
  <p>My question is, does the C++ compiler actually evaluate the function between the time I press the &quot;Build&quot; button and the time the compilation finishes? Or am I misunderstanding the keyword <code>constexpr</code>?</p>
  <p>EDIT: This program was compiled with <code>g++ 7.5.0</code> with <code>--std=c++17</code>.</p>