title: C++ ScopeTimer doesn't work
body: <p>I'm trying to implement a timer class which prints the time needed for a given scope. Somehow I can't get it to work properly. My code so far:</p>
  
  <p>Main.cpp: </p>
  
  <pre><code>    #include "scopetimer.hpp"
      #include &lt;cstdlib&gt;
      #include &lt;cmath&gt;
      #include &lt;string&gt;
      #include &lt;chrono&gt;
      #include &lt;iostream&gt;
  void work01()
  {
      double numbers[10000];
      for (int i = 0; i &lt; 10000; ++i)
      {
          numbers[i] = double(std::rand()) / double(RAND_MAX);
      }
      for (int n = 10000; n &gt; 1; n = n - 1) {
          for (int i = 0; i &lt; n - 1; i = i + 1) {
              if (numbers[i] &gt; numbers[i + 1]) {
                  double tmp = numbers[i];
                  numbers[i] = numbers[i + 1];
                  numbers[i + 1] = tmp;
              }
          }
      }
  }
  
  void work02()
  {
      int* buf[1024];
  
      for (int i = 2; i &lt; 1024; ++i)
          buf[i] = new int[i];
      for (int i = 2; i &lt; 1024; ++i)
          delete[] buf[i];
  }
  
  // counts the number of primes in an interval
  int work03(int n0, int n1)
  {
      int freq = n1 - n0 + 1;
      for (int i = n0; i &lt;= n1; ++i)
      {
          // Have fun: use the alternative iteration direction and see how fast
          // it gets!
          // for(int j = 2; j &lt; i; ++j)
          for (int j = i - 1; j &gt; 1; --j)
          {
              if (i%j == 0)
              {
                  --freq;
                  break;
              }
          }
      }
      return freq;
  }
  
  int main(int, char**)
  {
      {   ScopeTimer("work01");
          work01();
      }
      {
          ScopeTimer("work02");
          work02();
      }
      {
          ScopeTimer("work03");
          work03(0, 10000);   
      }
      std::cout &lt;&lt; std::endl &lt;&lt; "Tests" &lt;&lt; std::endl &lt;&lt; std::endl;
      {
          clock_t start_(std::clock());
          work01();
          clock_t end_(std::clock());
          std::cout &lt;&lt; "Test Timer: " &lt;&lt; end_ - start_ &lt;&lt; "ns" &lt;&lt; std::endl;
      }   
      {
          clock_t start_(std::clock());
          work02();
          clock_t end_(std::clock());
          std::cout &lt;&lt; "Test Timer: " &lt;&lt; end_ - start_ &lt;&lt; "ns" &lt;&lt; std::endl;
      }
      {
          clock_t start_(std::clock());
          work03(0,10000);
          clock_t end_(std::clock());
          std::cout &lt;&lt; "Test Timer: " &lt;&lt; end_ - start_ &lt;&lt; "ns" &lt;&lt; std::endl;
      }
  
      system("Pause");
  }
  
  
  scopetimer.cpp
  
          #include "scopetimer.hpp"
          #include &lt;cmath&gt;
          #include &lt;string&gt;
          #include &lt;chrono&gt;
          #include &lt;iostream&gt;
  
      ScopeTimer::ScopeTimer(const std::string&amp; name)
          :name_(name),
          start_(std::clock()) {
      }
  
      ScopeTimer::~ScopeTimer() {
          double elapsed = (double(std::clock() - start_) / double(CLOCKS_PER_SEC));
          std::cout &lt;&lt; name_ &lt;&lt; ": " &lt;&lt; int(elapsed) &lt;&lt; "ns" &lt;&lt; std::endl;
      }
  </code></pre>
  
  <p>I tested the clock functions outside of ScopeTimer(), which works fine. So the only issues, as far as I can tell, is that I can't get ScopeTimer() to work. It always prints 0ns. I mostly followed the turorial: <a href="https://felix.abecassis.me/2011/09/cpp-timer-raii/" rel="nofollow noreferrer">https://felix.abecassis.me/2011/09/cpp-timer-raii/</a></p>
  
  <p>Kind regards</p>