lemon/time_measure.h
changeset 536 97674155c135
parent 509 c5919679af17
parent 482 879c55700cd4
child 548 94387da47f79
equal deleted inserted replaced
15:8f2beadc9b00 16:f6f29b389758
    22 ///\ingroup timecount
    22 ///\ingroup timecount
    23 ///\file
    23 ///\file
    24 ///\brief Tools for measuring cpu usage
    24 ///\brief Tools for measuring cpu usage
    25 
    25 
    26 #ifdef WIN32
    26 #ifdef WIN32
    27 #ifndef WIN32_LEAN_AND_MEAN
    27 #include <lemon/bits/windows.h>
    28 #define WIN32_LEAN_AND_MEAN
       
    29 #endif
       
    30 #ifndef NOMINMAX
       
    31 #define NOMINMAX
       
    32 #endif
       
    33 #include <windows.h>
       
    34 #include <cmath>
       
    35 #else
    28 #else
    36 #include <unistd.h>
    29 #include <unistd.h>
    37 #include <sys/times.h>
    30 #include <sys/times.h>
    38 #include <sys/time.h>
    31 #include <sys/time.h>
    39 #endif
    32 #endif
    90       utime=ts.tms_utime/tck;
    83       utime=ts.tms_utime/tck;
    91       stime=ts.tms_stime/tck;
    84       stime=ts.tms_stime/tck;
    92       cutime=ts.tms_cutime/tck;
    85       cutime=ts.tms_cutime/tck;
    93       cstime=ts.tms_cstime/tck;
    86       cstime=ts.tms_cstime/tck;
    94 #else
    87 #else
    95       static const double ch = 4294967296.0e-7;
    88       bits::getWinProcTimes(rtime, utime, stime, cutime, cstime);
    96       static const double cl = 1.0e-7;
       
    97 
       
    98       FILETIME system;
       
    99       GetSystemTimeAsFileTime(&system);
       
   100       rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
       
   101 
       
   102       FILETIME create, exit, kernel, user;
       
   103       if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
       
   104         utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
       
   105         stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
       
   106         cutime = 0;
       
   107         cstime = 0;
       
   108       } else {
       
   109         rtime = 0;
       
   110         utime = 0;
       
   111         stime = 0;
       
   112         cutime = 0;
       
   113         cstime = 0;
       
   114       }
       
   115 #endif
    89 #endif
   116     }
    90     }
   117 
    91 
   118     /// Constructor initializing with zero
    92     /// Constructor initializing with zero
   119     TimeStamp()
    93     TimeStamp()