title: C++ performance: Local variable vs data member
body: <p>Suppose the code blow is my class. It's simplified and not complete. Let's focus on the implementation of <code>operator()</code>.</p>
  
  <pre><code>class Delta{
  public:
      long long operator()() {
          auto now = steady_clock::now(); 
          auto delta = (now - last).count();
          last = now;
          return delta;
      }
  private:
      steady_clock::time_point last;
  };
  </code></pre>
  
  <p><code>operator()</code> may be called thousands of times per second. I just wonder frequently allocate and deallocate variable <code>now</code> and <code>delta</code> may hurt the performance of <code>operator()</code>. So is it better to make <code>now</code> and <code>delta</code> data member of <code>class Delta</code> if I want to maximize the speed? But I also heard that local variable may not even exists when compiled. So somehow the overhead does not exists either.</p>
  
  <p>well, actually the speed of this operator doesn't make any difference to my Application's speed. I just wan't to know a compiler-neutral answer. When this situation comes. Should I make it data members or local variables?</p>