title: How can I measure CPU time in C++ on windows and include calls of system()?
body: <p>I want to run some benchmarks on a C++ algorithm and want to get the CPU time it takes, depending on inputs. I use Visual Studio 2012 on Windows 7. I already discovered one way to calculate the CPU time in Windows: <a href="https://stackoverflow.com/questions/17432502/how-can-i-measure-cpu-time-and-wall-clock-time-on-both-linux-windows">How can I measure CPU time and wall clock time on both Linux/Windows?</a></p>
  
  <p>However, I use the <a href="http://www.cplusplus.com/reference/cstdlib/system/" rel="nofollow noreferrer">system()</a> command in my algorithm, which is not measured that way. So, how can I measure CPU time and include the times of my script calls via system()?</p>
  
  <p>I should add a small example. This is my get_cpu_time-function (From the link described above):</p>
  
  <pre><code>double get_cpu_time(){
      FILETIME a,b,c,d;
      if (GetProcessTimes(GetCurrentProcess(),&amp;a,&amp;b,&amp;c,&amp;d) != 0){
          //  Returns total user time.
          //  Can be tweaked to include kernel times as well.
          return
              (double)(d.dwLowDateTime |
              ((unsigned long long)d.dwHighDateTime &lt;&lt; 32)) * 0.0000001;
      }else{
          //  Handle error
          return 0;
      }
  }
  </code></pre>
  
  <p>That works fine so far, and when I made a program, that sorts some array (or does some other stuff that takes some time), it works fine. However, when I use the system()-command like in this case, it doesn't:</p>
  
  <pre><code>int main( int argc, const char* argv[] )
  {
      double start = get_cpu_time();
      double end;
      system("Bla.exe");
      end = get_cpu_time();
  
      printf("Everything took %f seconds of CPU time", end - start);
  
      std::cin.get();
  
  }
  </code></pre>
  
  <p>The execution of the given exe-file is measured in the same way and takes about 5 seconds. When I run it via system(), the whole thing takes a CPU time of 0 seconds, which obviously does not include the execution of the exe-file.</p>
  
  <p>One possibility would be to get a HANDLE on the system call, is that possible somehow?</p>