DGtal  1.2.0
testClock.cpp
Go to the documentation of this file.
1 
34 #include <cstdio>
35 #include <cmath>
36 #include <iostream>
37 #include "DGtal/base/Common.h"
38 #include "DGtal/base/Clock.h"
39 
40 using namespace DGtal;
41 using namespace std;
42 
45 {
46  double tick;
47  Clock c;
48 
49  trace.info() << c <<std::endl;
50 
51  c.startClock();
52  tick = c.stopClock();
53  trace.info() << "Minimal tick: "<< tick <<endl;
54  return (tick >= 0);
55 }
56 
59 {
60  double tick,tmp=0;
61 
62  Clock c;
63  c.startClock();
64  for (unsigned int i=0 ; i< 4334450; i++)
65  tmp = cos(tmp+i);
66 
67  tick = c.stopClock();
68  trace.info()<< "Loop tick: "<< tick <<endl;
69  return (tick >= 0);
70 }
71 
74 {
75  double tick1,tick2,tick3,tmp=0;
76 
77  Clock c,c2,c3;
78 
79  c3.startClock();
80  c.startClock();
81  for (unsigned int i=0 ; i< 43350; i++)
82  tmp = cos(tmp+i);
83 
84  c2.startClock();
85  for (unsigned int i=0 ; i< 43350; i++)
86  tmp = cos(tmp+i);
87 
88  tick2 = c2.stopClock();
89 
90  for (unsigned int i=0 ; i< 43450; i++)
91  tmp = cos(tmp+i);
92 
93  tick1 = c.stopClock();
94  tick3=c3.stopClock();
95 
96  trace.info()<< "Loop tick1: "<< tick1
97  <<" Loop tick2: "<< tick2
98  << " total: "<< tick3 <<endl;
99  return ((tick3 >= tick1) && (tick1 >= 0));
100 }
101 
104 {
105  double tmp = 0.0;
106  double tick_total=0., tick_accum=0.;
107  Clock c_total, c_accum;
108 
109  c_total.startClock();
110  c_accum.startClock();
111 
112 #if !defined(WIN32)
113 
114  for (unsigned int i=0 ; i< 43350; i++)
115  tmp = cos(tmp+i);
116  usleep(20000);
117  tick_accum += c_accum.restartClock();
118 
119  for (unsigned int i=0 ; i< 43350; i++)
120  tmp = cos(tmp+i);
121  usleep(20000);
122  tick_accum += c_accum.restartClock();
123 
124  for (unsigned int i=0 ; i< 43350; i++)
125  tmp = cos(tmp+i);
126  usleep(20000);
127  tick_accum += c_accum.restartClock();
128 
129  tick_total = c_total.stopClock();
130 
131  double delta = tick_total-tick_accum;
132 
133  trace.info()<< "Loop tick_total: " << tick_total
134  << " Loop tick_accum: " << tick_accum
135  << " Delta = "<<delta << endl;
136 
137  //return delta>=0 && delta<1e-4;
138 #endif
139  return true;
140 }
141 
142 
143 
144 int main()
145 {
147  return 0;
148  else
149  return 1;
150 
151 }
double restartClock()
void startClock()
double stopClock() const
std::ostream & info()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
bool test_RestartClock()
Test restart.
Definition: testClock.cpp:103
bool test_loopTick()
Loop ticks must be >=0.
Definition: testClock.cpp:58
bool test_minimalTick()
Minimal tick must be >=0.
Definition: testClock.cpp:44
bool test_MultipleLoop()
Test several loops.
Definition: testClock.cpp:73
int main()
Definition: testClock.cpp:144