Peano
Loading...
Searching...
No Matches
Watch.h
Go to the documentation of this file.
1// Copyright (C) 2009 Technische Universitaet Muenchen
2// This file is part of the Peano project. For conditions of distribution and
3// use, please see the copyright notice at www.peano-framework.org
4#pragma once
5
6
7#include <chrono>
8#include <ctime>
9
10
11#include "tarch/logging/Log.h"
12
13
14namespace tarch::timing {
15 class Watch;
16} // namespace tarch::timing
17
18
46private:
51
57
61 std::string _operationName;
62
66 std::clock_t _startClockTicks;
67
71 std::chrono::steady_clock::time_point _startTime; // steady_clock replaced
72 // the
73 // high_resolution_clock
74 // as the latter can be
75 // jumpy.
76
80 std::clock_t _elapsedClockTicks;
81
86
91
92public:
100 Watch(
101 const std::string& className,
102 const std::string& operationName,
103 bool plotResultInDestructor,
104 bool startToTickImmediately = true
105 );
106
112 virtual ~Watch();
113
125 void start();
126
127
135 void stop();
136
137
154 double getCPUTime();
155
160 std::clock_t getCPUTicks();
161
167 double getCalendarTime();
168
175 bool isOn() const;
176};
Log Device.
Definition Log.h:516
A simple class that has to be included to measure the clock ticks required for an operation.
Definition Watch.h:45
tarch::logging::Log _log
Log device the result is written to.
Definition Watch.h:50
Watch(const std::string &className, const std::string &operationName, bool plotResultInDestructor, bool startToTickImmediately=true)
Construct a watch.
Definition Watch.cpp:10
double getCalendarTime()
This method returns the elapsed calendar time between the start and stop command of the timer,...
Definition Watch.cpp:74
std::clock_t getCPUTicks()
Equals getCPUTime() but returns the clock ticks instead of the time in seconds.
Definition Watch.cpp:71
bool _isRunning
Has stopTimer() been called before.
Definition Watch.h:90
double getCPUTime()
Return CPU Time in Seconds.
Definition Watch.cpp:64
bool _plotResultInDestructor
Flag to distinguish the (original) standard watch.
Definition Watch.h:56
void stop()
Stop timer.
Definition Watch.cpp:55
bool isOn() const
This operation returns whether the watch is currently on.
Definition Watch.cpp:77
void start()
(Re)Start the Timer
Definition Watch.cpp:48
virtual ~Watch()
For standard version (): Stops the watch and plots the time spent.
Definition Watch.cpp:31
double _elapsedTime
Holds the elapsed calendar time.
Definition Watch.h:85
std::clock_t _elapsedClockTicks
Holds the elapsed processor time.
Definition Watch.h:80
std::chrono::steady_clock::time_point _startTime
Holds the time at the beginning of the time measurement.
Definition Watch.h:71
std::clock_t _startClockTicks
Holds the clock ticks at the beginning of the time measurement.
Definition Watch.h:66
std::string _operationName
Stores the name of the operation the watch is used within.
Definition Watch.h:61