ACT-CV - Machine Vision for Cognitive Modeling
StoppUhr.h
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2 
3 /*
4 ACT-CV - Machine Vision for Cognitive Modeling
5 Copyright (c) 2008 Marc Halbruegge
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
22 
28 #ifndef __STOPPUHR_H
29 #define __STOPPUHR_H
30 
31 #include <time.h>
32 
35 protected:
36  clock_t start, ende;
37 public:
38  void Start() {
39  start=clock();
40  }
41  void Ende() {
42  ende=clock();
43  }
44  double GetSeconds() const {
45  double zeit=ende-start;
46  zeit/=CLOCKS_PER_SEC;
47  return zeit;
48  }
49  double GetMSec() const {
50  return GetSeconds()*1000.0;
51  }
52 };
53 
54 
56 class StoppUhrTime {
57 protected:
58  time_t start, ende;
59 public:
60  void Start() {
61  start=time(NULL);
62  }
63  void Ende() {
64  ende=time(NULL);
65  }
66  double GetSeconds() const {
67  double zeit=difftime(ende,start);
68  return zeit;
69  }
70  double GetMSec() const {
71  return GetSeconds()*1000.0;
72  }
73 };
74 
75 
78 protected:
79  time_t zeit[2];
80  int idx;
81  int n;
82 public:
84  Start();
85  }
86  void Start() {
87  idx=0;
88  n=0;
89  }
90  void Messung() {
91  zeit[idx++]=time(NULL);
92  idx%=2;
93 
94  if (n<2) n++;
95  }
97  double GetSeconds() const {
98  if (n<2) return -1;
99  double curTime=difftime(zeit[(idx+1)%2],zeit[idx]);
100  return curTime;
101  }
103  double GetMSec() const {
104  return GetSeconds()*1000.0;
105  }
106 };
107 
110 protected:
111  clock_t zeit[2];
112  int idx;
113  int n;
114 public:
116  Start();
117  }
118  void Start() {
119  idx=0;
120  n=0;
121  }
122  void Messung() {
123  zeit[idx++]=clock();
124  idx%=2;
125 
126  if (n<2) n++;
127  }
129  double GetSeconds() const {
130  if (n<2) return -1;
131  double curTime=zeit[(idx+1)%2]-zeit[idx];
132  curTime/=CLOCKS_PER_SEC;
133  return curTime;
134  }
136  double GetMSec() const {
137  return GetSeconds()*1000.0;
138  }
139 };
140 
141 #endif


ACT-CV - Machine Vision for Cognitive Modeling
© 2015 Marc Halbruegge (actcvlibrary@googlemail.com)