iipsrv 1.2
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
Timer.h
1/* IIPImage server :: Timer class
2
3 Copyright (C) 2005-2022 Ruven Pillay.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20
21#ifndef _TIMER_H
22#define _TIMER_H
23
24
25#ifdef HAVE_SYS_TIME_H
26#include <sys/time.h>
27#endif
28
29// Use the STL chrono classes if available
30#ifdef HAVE_STL_CHRONO
31#include <chrono>
32#endif
33
34#ifdef WIN32
35#include "../windows/Time.h"
36#endif
37
39
40class Timer {
41
42
43 private:
44
45#ifdef HAVE_STL_CHRONO
47 std::chrono::time_point<std::chrono::high_resolution_clock> start_t;
48#else
49
51 struct timeval tv;
52
54 struct timezone tz;
55
57 long start_t;
58
60 long start_u;
61
62#endif
63
64
65public:
66
68 Timer() {};
69
70
72
73 void start() {
74#ifdef HAVE_STL_CHRONO
75 start_t = std::chrono::high_resolution_clock::now();
76#else
77 tz.tz_minuteswest = 0;
78 if( gettimeofday( &tv, NULL ) == 0 ){
79 start_t = tv.tv_sec;
80 start_u = tv.tv_usec;
81 }
82 else start_t = start_u = 0;
83#endif
84 }
85
86
88 long getTime() {
89#ifdef HAVE_STL_CHRONO
90 auto d = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now() - start_t );
91 return d.count();
92#else
93 if( gettimeofday( &tv, NULL ) == 0 ) return (tv.tv_sec - start_t) * 1000000 + (tv.tv_usec - start_u);
94 else return 0;
95#endif
96 }
97
98
99};
100
101
102#endif
Simple Timer class to allow us to time our responses.
Definition: Timer.h:40
void start()
Set our time.
Definition: Timer.h:73
Timer()
Constructor.
Definition: Timer.h:68
long getTime()
Return time since we were initialised in microseconds.
Definition: Timer.h:88