fw4spl
HiResClock.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwCore/HiResClock.hpp"
8 
9 
10 #ifdef WIN32
11 #include <windows.h>
12 #else
13 #include <sys/time.h>
14 #endif
15 
16 #include <cstdlib>
17 
18 
19 namespace fwCore
20 {
21 
22 namespace HiResClock
23 {
24 
26 {
27  HiResClockType TimeInMicroSec;
28 
29 #ifdef WIN32
30  LARGE_INTEGER count;
31  LARGE_INTEGER frequency;
32  QueryPerformanceFrequency(&frequency);
33  QueryPerformanceCounter(&count);
34 
35  TimeInMicroSec = count.QuadPart * (1000000.0 / frequency.QuadPart);
36 #else
37  timeval count;
38  gettimeofday(&count, NULL);
39 
40  TimeInMicroSec = (count.tv_sec * 1000000.0) + count.tv_usec;
41 #endif
42 
43  return TimeInMicroSec;
44 }
45 
47 {
48  return getTimeInMicroSec() * 0.001;
49 }
50 
51 
53 {
54  return getTimeInMicroSec() * 0.000001;
55 }
56 
57 } //namespace HiResClock
58 
59 } //namespace fwCore
This namespace fwCore provides common foundations for FW4SPL.
Definition: BaseObject.hpp:16
FWCORE_API HiResClockType getTimeInMilliSec()
Definition: HiResClock.cpp:46
double HiResClockType
Type returned by HiResClock Functions.
Definition: HiResClock.hpp:29
FWCORE_API HiResClockType getTimeInMicroSec()
Definition: HiResClock.cpp:25
FWCORE_API HiResClockType getTimeInSec()
Definition: HiResClock.cpp:52