cgma
CpuTimer Class Reference

#include <CpuTimer.hpp>

List of all members.

Public Member Functions

 CpuTimer ()
double cpu_secs ()
double clock_secs ()
double elapsed (bool wall_time=false)

Private Attributes

time_t cpu
time_t cpuInitial
timeval wallTimeInitial
timeval wallTime

Detailed Description

Definition at line 14 of file CpuTimer.hpp.


Constructor & Destructor Documentation

Definition at line 46 of file CpuTimer.cpp.

{
  tms current;

  // Added by Cat for WIN32 port
#ifdef _WIN32
  nt_times(&current);
  wallTimeInitial = clock();
  wallTime = wallTimeInitial;
#else
  gettimeofday(&wallTimeInitial, NULL);
  wallTime = wallTimeInitial;
  times( &current );
#endif
  
  // Store current value of cpu time
  cpu = current.tms_utime +
        current.tms_stime +
        current.tms_cutime +
        current.tms_cstime;
  cpuInitial = cpu;
}

Member Function Documentation

Definition at line 97 of file CpuTimer.cpp.

{
  double elapsed_time;
#ifdef _WIN32
  clock_t current;
  current = clock();
  elapsed_time = double( current - wallTime );
  elapsed_time = elapsed_time / HZ;

  wallTime = current;
#else
  timeval current;
  gettimeofday( &current, NULL );
  double prev_time = wallTime.tv_sec;
  prev_time += double( wallTime.tv_usec ) / 1000000.0;
  
  elapsed_time = current.tv_sec;
  elapsed_time += double( current.tv_usec ) / 1000000.0;
  elapsed_time = elapsed_time - prev_time;
  
  wallTime = current;
#endif
  
  return elapsed_time;
}
double CpuTimer::cpu_secs ( )

Definition at line 72 of file CpuTimer.cpp.

{
  tms current;

  // Added by Cat for WIN32 port
#ifdef _WIN32
  nt_times(&current);    
#else
  times( &current );
#endif
  
  time_t cpu_now = current.tms_utime +
    current.tms_stime +
    current.tms_cutime +
    current.tms_cstime;
  time_t delta = cpu_now - cpu;
  cpu   = cpu_now;
#ifdef _WIN32
  if( delta == 0 )
     delta = 1;
#endif
  return (double) delta / HZ;
}
double CpuTimer::elapsed ( bool  wall_time = false)

Definition at line 124 of file CpuTimer.cpp.

{
  if( wall_time )
  {
    double elapsed;
#ifdef _WIN32
    clock_t current;
    current = clock();
    elapsed = double( current - wallTimeInitial);
    elapsed = elapsed / HZ;
#else    
    double current_time;
    timeval current;
    gettimeofday( &current, NULL );
    double initial_time;
    initial_time = wallTimeInitial.tv_sec;
    initial_time += double(wallTimeInitial.tv_usec) / 1000000.0;
    current_time = current.tv_sec;
    current_time += double( current.tv_usec ) / 1000000.0;
    
    elapsed = current_time - initial_time;
#endif
    return elapsed;
  }
  else
  {
    tms current;

// Added by Cat for WIN32 port
#ifdef _WIN32
    nt_times(&current);    
#else
    times( &current );
#endif
// Store totals
  
    time_t cpu_now = current.tms_utime +
        current.tms_stime +
        current.tms_cutime +
        current.tms_cstime;
    time_t elapsed = cpu_now - cpuInitial;
    return (double) elapsed / HZ;
  }
}

Member Data Documentation

time_t CpuTimer::cpu [private]

Definition at line 25 of file CpuTimer.hpp.

time_t CpuTimer::cpuInitial [private]

Definition at line 27 of file CpuTimer.hpp.

timeval CpuTimer::wallTime [private]

Definition at line 37 of file CpuTimer.hpp.

timeval CpuTimer::wallTimeInitial [private]

Definition at line 36 of file CpuTimer.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines