DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testClock.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/base/Clock.h"

Go to the source code of this file.

Functions

bool test_minimalTick ()
 Minimal tick must be >=0. More...
 
bool test_loopTick ()
 Loop ticks must be >=0. More...
 
bool test_MultipleLoop ()
 Test several loops. More...
 
bool test_RestartClock ()
 Test restart. More...
 
int main ()
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr )
Date
2009/12/13

This file is part of the DGtal library

Definition in file testClock.cpp.

Function Documentation

◆ main()

int main ( void  )

Definition at line 144 of file testClock.cpp.

145{
147 return 0;
148 else
149 return 1;
150
151}
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

References test_loopTick(), test_minimalTick(), test_MultipleLoop(), and test_RestartClock().

◆ test_loopTick()

bool test_loopTick ( )

Loop ticks must be >=0.

Definition at line 58 of file testClock.cpp.

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}
void startClock()
std::ostream & info()
Trace trace
Definition: Common.h:154

References DGtal::Trace::info(), DGtal::Clock::startClock(), and DGtal::trace.

Referenced by main().

◆ test_minimalTick()

bool test_minimalTick ( )

Minimal tick must be >=0.

Definition at line 44 of file testClock.cpp.

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}

References DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ test_MultipleLoop()

bool test_MultipleLoop ( )

Test several loops.

Definition at line 73 of file testClock.cpp.

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}
double stopClock() const

References DGtal::Trace::info(), DGtal::Clock::startClock(), DGtal::Clock::stopClock(), and DGtal::trace.

Referenced by main().

◆ test_RestartClock()

bool test_RestartClock ( )

Test restart.

Definition at line 103 of file testClock.cpp.

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}
double restartClock()

References DGtal::Trace::info(), DGtal::Clock::restartClock(), DGtal::Clock::startClock(), DGtal::Clock::stopClock(), and DGtal::trace.

Referenced by main().