Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | werner | 1 | /******************************************************************************************** |
2 | ** iLand - an individual based forest landscape and disturbance model |
||
3 | ** http://iland.boku.ac.at |
||
4 | ** Copyright (C) 2009- Werner Rammer, Rupert Seidl |
||
5 | ** |
||
6 | ** This program 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 | ** 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 General Public License for more details. |
||
15 | ** |
||
16 | ** You should have received a copy of the GNU General Public License |
||
17 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | ********************************************************************************************/ |
||
19 | |||
72 | Werner | 20 | #include "ticktack.h" |
145 | Werner | 21 | #include <QtCore> |
72 | Werner | 22 | |
86 | Werner | 23 | /* TODO: this is purely WINDOWS - provide a version for other BS, change the build-system |
24 | to only use this on Win. |
||
25 | */ |
||
780 | werner | 26 | #ifdef Q_OS_WIN |
145 | Werner | 27 | #include <windows.h> |
28 | |||
72 | Werner | 29 | class TTickTack |
30 | { |
||
31 | private: |
||
32 | _LARGE_INTEGER starttime; |
||
33 | |||
34 | _LARGE_INTEGER getCount() |
||
35 | { |
||
36 | _LARGE_INTEGER value; |
||
37 | QueryPerformanceCounter(&value); |
||
38 | return value; |
||
39 | } |
||
40 | public: |
||
41 | TTickTack() { reset(); } |
||
42 | void reset() { starttime = getCount(); } |
||
43 | double elapsed() { |
||
44 | _LARGE_INTEGER stoptime = getCount(); |
||
45 | __int64 start = starttime.QuadPart; |
||
46 | __int64 end = stoptime.QuadPart; |
||
47 | __int64 elapsed = end - start; |
||
48 | _LARGE_INTEGER freq; |
||
49 | QueryPerformanceFrequency(&freq); |
||
50 | double seconds = elapsed / double(freq.QuadPart); |
||
51 | return seconds; |
||
52 | |||
53 | } |
||
54 | }; |
||
145 | Werner | 55 | #else |
996 | werner | 56 | // non windows implementation |
57 | #include <QElapsedTimer> |
||
145 | Werner | 58 | class TTickTack |
59 | { |
||
60 | public: |
||
996 | werner | 61 | TTickTack() { reset(); } |
62 | void reset() { t.start(); } |
||
997 | werner | 63 | double elapsed() { return t.elapsed()/1000.; } |
996 | werner | 64 | private: |
65 | QElapsedTimer t; |
||
145 | Werner | 66 | }; |
67 | #endif |
||
72 | Werner | 68 | |
69 | TickTack::TickTack() |
||
70 | { |
||
71 | d = new TTickTack(); |
||
72 | d->reset(); |
||
73 | } |
||
74 | TickTack::~TickTack() |
||
75 | { |
||
76 | delete d; |
||
77 | } |
||
78 | |||
79 | void TickTack::start() |
||
80 | { |
||
81 | d->reset(); |
||
82 | } |
||
83 | |||
84 | double TickTack::elapsed() |
||
85 | { |
||
86 | return d->elapsed(); |
||
87 | } |