Flow123d
DF_profiler_memory_monitor-83fd579
src
system
time_point.hh
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4
*
5
* This program is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License version 3 as published by the
7
* Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
*
13
*
14
* @file time_point.hh
15
* @brief
16
*/
17
18
#ifndef TIMEPOINT_HH_
19
#define TIMEPOINT_HH_
20
21
22
23
/**
24
* Class TimerData serves for getting current time in ticks units.
25
* TimerData overloads standard + and - operators so object can be
26
* subtracted/added from/to one another.
27
*
28
* TimerData uses one if the following timers based
29
* on set definition namely:
30
*
31
* 1) FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
32
* It is used Timer for Windows platform only.
33
*
34
* Method QueryPerformanceCounter populates given
35
* LARGE_INTEGER object with timer informations.
36
* Resolution if this timer is several hundreds ns.
37
* Tests have shown average about 300 ns.
38
* Maximum resolution is 1 ns.
39
*
40
*
41
* 2) FLOW123D_HAVE_TIMER_CHRONO_HIGH_RESOLUTION (default without definition set)
42
* It is used standard multiplatform Chrono Timer
43
* which is available since C++11 (compile flag -std=cxx11 required!)
44
*
45
* Resolution of timer depends on HW but tests shown results fluctuating around 1000 ns.
46
* Maximum resolution is 1 ns.
47
*
48
*
49
* Note:
50
* Standard clock() method available in c++ yields
51
* resolution in units of milliseconds (roughly 10 ms)
52
* but some compilers replaces during compilation
53
* method clock() with better Timer having resolution 1000 ns.
54
* Meaning clock() method is not sufficient or stable
55
* for time measurements.
56
* Maximum resolution is 1000 ns (limited by value of CLOCKS_PER_SEC).
57
*
58
* gettimeofday
59
* The actual resolution of gettimeofday() depends on the hardware architecture. Intel
60
* processors as well as SPARC machines offer high resolution timers that measure microseconds.
61
* Other hardware architectures fall back to the system’s timer, which is typically set to 100 Hz.
62
* In such cases, the time resolution will be less accurate. gettimeofday() can result in incorrect
63
* timings if there are processes on your system that change the timer
64
* Possible solution may be other clock
65
*
66
* clock_gettime (CLOCK_MONOTONIC) with clock_getres() method
67
* but clock_gettime is present only on newest Linux. other system have only gettimeofday()
68
*/
69
class
TimePoint
{
70
public
:
71
72
/**
73
* Constructor will populate object with current time
74
*/
75
TimePoint
();
76
77
/**
78
* Overloaded operator for subtraction. Allows subtracting TimerPoint objects using '-' sign
79
* Used for determining interval between two TimerPoints
80
*
81
* Returns duration in seconds
82
*/
83
double
operator-
(
const
TimePoint
&
right
);
84
85
/**
86
* Internal variable for storing actual ticks
87
*/
88
long
long
ticks
;
89
90
private
:
91
92
#ifdef FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
93
/**
94
* Variable for storing CPU Frequency
95
*/
96
static
LARGE_INTEGER frequency;
97
98
/**
99
* Init function which sets current CPU frequency
100
* and returns it
101
*/
102
static
LARGE_INTEGER get_frequency ();
103
#endif
//FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
104
105
};
106
#endif
/* TIMEPOINT_HH_ */
TimePoint
Definition:
time_point.hh:69
TimePoint::operator-
double operator-(const TimePoint &right)
Definition:
time_point.cc:77
TimePoint::ticks
long long ticks
Definition:
time_point.hh:88
TimePoint::TimePoint
TimePoint()
Definition:
time_point.cc:71
LimitSide::right
@ right
Generated by
1.9.1