1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee 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 General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef _MYTIME_
20 #define _MYTIME_
21 
22 #ifdef WIN32
23 #include <windows.h>
24 #elif defined __APPLE__
25 #include <sys/time.h>
26 #else
27 #include <ctime>
28 #endif
29 
30 class MyTime
31 {
32 
33 public:
34 #ifndef WIN32
35     timespec t;
36 #else
37     LONGLONG t;
38     LONGLONG baseFrequency;
39     MyTime()
40     {
41         LARGE_INTEGER ulf;
42         QueryPerformanceFrequency(&ulf);
43         baseFrequency = ulf.QuadPart;
44         QueryPerformanceCounter(&ulf);
45         t = ulf.QuadPart;
46     }
47 #endif
48 
set()49     void set ()
50     {
51 #ifdef WIN32
52         LARGE_INTEGER ulf;
53         QueryPerformanceCounter(&ulf);
54         t = ulf.QuadPart;
55 #elif defined __APPLE__
56         struct timeval tv;
57         gettimeofday(&tv, NULL);
58         t.tv_sec = tv.tv_sec;
59         t.tv_nsec = tv.tv_usec * 1000;
60 #else
61         clock_gettime (CLOCK_REALTIME, &t);
62 #endif
63     }
64 
etime(MyTime a)65     int etime (MyTime a)
66     {
67 #ifndef WIN32
68         return (t.tv_sec - a.t.tv_sec) * 1000000 + (t.tv_nsec - a.t.tv_nsec) / 1000;
69 #else
70         return (t - a.t) * 1000 / (baseFrequency / 1000);
71 #endif
72     }
73 };
74 
75 
76 #endif
77