source: GTP/trunk/Lib/Vis/Preprocessing/src/havran/timer.h @ 2582

Revision 2582, 2.6 KB checked in by bittner, 17 years ago (diff)

Havran Ray Caster compiles and links, but still does not work

Line 
1// ================================================================
2// $Id: timer.h,v $
3//
4// timer.h
5//     CTimer class to measure the elapsed time
6//
7// Class: CTimer
8//
9// REPLACEMENT_STRING
10//
11// Copyright by Vlastimil Havran, 2007 - email to "vhavran AT seznam.cz"
12// Initial coding by Vlastimil Havran, 1998.
13
14#ifndef __TIMER_H__
15#define __TIMER_H__
16
17// GOLEM headers
18#include "configh.h"
19
20// standard headers
21#ifdef __UNIX__
22#include <sys/resource.h>
23#endif
24
25#include <ctime>
26
27namespace GtpVisibilityPreprocessor {
28
29// Class CTimer is designed to measure the user/(user+system)/real time
30// taken by the processor within a portion of source code.
31class CTimer
32{
33private: // data
34#ifdef __UNIX__
35  // timing in OS UNIX
36  mutable struct rusage begrusage;
37  mutable struct rusage endrusage;
38#endif // __UNIX__
39
40  /// true if InitTiming() has already been called
41  static bool initTimingCalled;
42
43  /// accumulated real time (returned by RealTime() method)
44  mutable double realTime;
45  /// accumulated userTime
46  mutable double userTime;
47  /// accumulated user+system time
48  mutable double systemTime;
49  /// real time at the last start event
50  mutable double lastRealTime;
51  /// user time at the last start event
52  mutable double lastUserTime;
53  /// system time at the last start event
54  mutable double lastSystemTime;
55
56  /// the number of stopping this timer
57  mutable int  countStop;
58  /// if the timer is running at this time
59  mutable bool running;   
60
61private: // methods
62
63  /// interior implementation of Stop()
64  void _start() const;
65  // interior implementation of Start()
66  void _stop() const;
67
68  /// finds out whether performance timer is present (WIN32)
69  void _initTiming();
70
71public: // methods
72
73  /// default constructor
74  CTimer() { Reset();  if( ! initTimingCalled ) _initTiming();  }
75  /// default destructor
76  ~CTimer() {}
77  /// reset the time to zero all time values
78  void Reset();
79  /// restart the timer from zero
80  void Restart() { Reset(); Start();}
81  /// start/restart the timer to measure the following events
82  void Start() { _start(); }
83  /// stop the timer not to measure the following events
84  void Stop()  { _stop(); }
85  /// returns true if timer is running, otherwise false
86  bool IsRunning() const { return running;}
87  /// returns the real time measured by timer in seconds
88  double RealTime() const;
89  /// returns the user time measured by timer in seconds
90  double UserTime() const;
91  /// returns the user+system time measured by timer in seconds
92  double SystemTime() const;
93};
94
95
96}
97
98#endif // __TIMER_H__
Note: See TracBrowser for help on using the repository browser.