JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtphighrestimer.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>) (DKFZ) & IWR, University of Heidelberg
3
4 last modification: $LastChangedDate: 2015-06-10 19:19:10 +0200 (Mi, 10 Jun 2015) $ (revision $Rev: 3976 $)
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21
22#include <cmath>
23#include <cstdlib>
24#include <iostream>
25#include <chrono>
26
27#include "jkqtcommon_imexport.h"
28
29#ifndef __WINDOWS__
30# if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)
31# define __WINDOWS__
32# endif
33#endif
34
35#ifndef __LINUX__
36# if defined(linux)
37# define __LINUX__
38# endif
39#endif
40
41#if defined(__WINDOWS__)
42 #include<windows.h>
43#elif defined(__LINUX__)
44 #include <sys/time.h>
45#else
46 #include <sys/time.h>
47#endif
48
49
50
51#ifndef JKQTPHIGHRESTIMER_H
52#define JKQTPHIGHRESTIMER_H
53
54
55/**
56 * \brief This class implements a high resolution timer capable of measuring time intervals with a resolution
57 * of some microseconds
58 * \ingroup jkqtptools_debugging
59 *
60 * \attention Note that this is a MS Windows specific implementation od a high-resolution timer using some of
61 * windows' API methods (namely \c QueryPerformanceCounter() and \c QueryPerformanceFrequency() ). So if you want
62 * to use this class on non-win32 systems you will have to find a way to implement it for your system!!!
63 *
64 * \attention Also note that a standard windows system is NOT a real time OS. So do not expect to get a high accuracy
65 * when timing operations using this timer. It gives you an accurate time stamp, but it can not guarantee when
66 * the code is executed!
67 *
68 *
69 * The timer works very simple:
70 * - you can start the timer with start() which means you set a time=0
71 * - then you can query the time difference to the last call of start() by using getTime().
72 * .
73 *
74 *
75 * \par win32 implementation issues:
76 * To implement this timer on windows systems I use two API calls from the windows kernel. They are:
77 * <ul>
78 * <li> <a href="http://msdn2.microsoft.com/en-us/library/ms644904.aspx">QueryPerformanceCounter()</a>
79 * <li> <a href="http://msdn2.microsoft.com/en-us/library/ms644905.aspx">QueryPerformanceFrequency()</a>
80 * </ul>
81 * \n
82 * The first one is used to read times: In the start() method we simply save the current counter value to a variable.
83 * In getTime() we can then again use QueryPerformanceCounter() to get the current counter value and then calculate
84 * the difference between these two. Using QueryPerformanceFrequency() we can calculate the time difference in usecs
85 * from the counter value difference using:
86 * \f[ \Delta t=\frac{N_{\mbox{now}}-N_{\mbox{start}}}{\mbox{\texttt{QueryPerformanceFrequency()}}}\cdot 10^{6} \f]
87 *
88 */
90 protected:
91#ifdef __WINDOWS__
92 /** \brief internal: time stamp of the last call of start() */
93 LARGE_INTEGER last;
94#else
95 std::chrono::system_clock::time_point last;
96#endif
97 /** \brief internal: timer frequency */
98 double freq;
99 public:
100 /** \brief class constructor. */
102 /** \brief class destructor */
104 /** \brief start the timer */
105 void start();
106 /** \brief get the time since the last call of start() in microseconds */
107 double getTime();
108};
109
110
111
112
113
114#endif // JKQTPHIGHRESTIMER_H
This class implements a high resolution timer capable of measuring time intervals with a resolution o...
Definition jkqtphighrestimer.h:89
double freq
internal: timer frequency
Definition jkqtphighrestimer.h:98
double getTime()
get the time since the last call of start() in microseconds
void start()
start the timer
JKQTPHighResTimer()
class constructor.
~JKQTPHighResTimer()
class destructor
std::chrono::system_clock::time_point last
Definition jkqtphighrestimer.h:95
#define JKQTCOMMON_LIB_EXPORT
Definition jkqtcommon_imexport.h:87