Google OR-Tools: ortools/base/timer.h Source File

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef ORTOOLS_BASE_TIMER_H_

15#define ORTOOLS_BASE_TIMER_H_

16

17#include <cstdint>

18

19#include "absl/time/clock.h"

20#include "absl/time/time.h"

21

23 public:

26 running_ = false;

27 sum_ = 0;

28 }

29

31 running_ = true;

32 start_ = absl::GetCurrentTimeNanos();

33 }

39 if (running_) {

40 sum_ += absl::GetCurrentTimeNanos() - start_;

41 running_ = false;

42 }

43 }

48 return absl::Nanoseconds(GetNanos());

49 }

50 bool IsRunning() const { return running_; }

51

52 protected:

54 return running_ ? absl::GetCurrentTimeNanos() - start_ + sum_ : sum_;

55 }

56

57 private:

58 bool running_;

59 int64_t start_;

60 int64_t sum_;

61};

62

63

64

66

67

68

69

70

71

78

80

81

83 public:

86

88 return static_cast<int64_t>(s * 1e9);

89 }

91 static int64_t CyclesToMs(int64_t c) { return c / 1000000; }

92 static int64_t CyclesToUsec(int64_t c) { return c / 1000; }

93};

95

96

97

99

101 public:

102

103

104

107

108 private:

109 double* aggregate_time_;

110

111

113};

114#endif

static int64_t SecondsToCycles(double s)

Definition timer.h:87

static int64_t CyclesToUsec(int64_t c)

Definition timer.h:92

CycleTimerBase & operator=(const CycleTimerBase &)=delete

CycleTimerBase(const CycleTimerBase &)=delete

static double CyclesToSeconds(int64_t c)

Definition timer.h:90

static int64_t CyclesToMs(int64_t c)

Definition timer.h:91

int64_t GetCycles() const

Definition timer.h:76

ScopedWallTime(double *aggregate_time)

int64_t GetInUsec() const

Definition timer.h:46

bool IsRunning() const

Definition timer.h:50

double Get() const

Definition timer.h:44

WallTimer()

Definition timer.h:24

absl::Duration GetDuration() const

Definition timer.h:47

int64_t GetInMs() const

Definition timer.h:45

void Restart()

Definition timer.h:34

void Reset()

Definition timer.h:25

int64_t GetNanos() const

Definition timer.h:53

void Start()

Definition timer.h:30

void Stop()

Definition timer.h:38

WallTimer UserTimer

Definition timer.h:65

CycleTimerBase CycleTimerInstance

Definition timer.h:94

WallTimer ClockTimer

Definition timer.h:98

CycleTimer SimpleCycleTimer

Definition timer.h:79