I want to run some tests on the C ++ algorithm and I want to get the processor time it takes, depending on the input. I am using Visual Studio 2012 on Windows 7. I already discovered one way to calculate CPU time on Windows: How can I measure CPU time and wall clock on Linux / Windows?
However, I use system () in my algorithm, which is not measured this way. So, how can I measure the processor time and enable the time of my script calls through system ()?
I have to add a small example. This is my get_cpu_time function (from the link described above):
double get_cpu_time(){ FILETIME a,b,c,d; if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0){ // Returns total user time. // Can be tweaked to include kernel times as well. return (double)(d.dwLowDateTime | ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001; }else{ // Handle error return 0; } }
This works so far, and when I created the program, it sorts some array (or does some other things that take some time), it works fine. However, when I use the system () command, as in this case, this is not the case:
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(); }
The execution of this exe file is measured in the same way and takes about 5 seconds. When I run it through system (), all this takes a processor time of 0 seconds, which, obviously, does not include the execution of an exe file.
One possibility would be to get a HANDLE on a system call, is this possible somehow?