Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testTime.cpp
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Time management.
32
*/
33
41
#include <visp3/core/vpConfig.h>
42
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
// UNIX
43
#include <unistd.h>
44
#elif defined(_WIN32)
45
// #include <mmsystem.h>
46
// #include <winbase.h>
47
48
// Mute warning with clang-cl
49
// warning : non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
50
#if defined(__clang__)
51
# pragma clang diagnostic push
52
# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
53
#endif
54
55
#include <windows.h>
56
57
#if defined(__clang__)
58
# pragma clang diagnostic pop
59
#endif
60
61
#endif
62
#include <cmath>
63
#include <iostream>
64
#include <stdio.h>
65
#include <stdlib.h>
66
#include <time.h>
67
68
#include <visp3/core/vpTime.h>
69
70
int
main()
71
{
72
#ifdef ENABLE_VISP_NAMESPACE
73
using namespace
VISP_NAMESPACE_NAME
;
74
#endif
75
#if !defined(WINRT)
76
try
{
77
double
v
= 0;
78
79
double
t0 =
vpTime::measureTimeMs
();
80
for
(
int
i = 0;
i
< 100000;
i
++)
81
for
(
int
j = 0;
j
< 100;
j
++)
82
v = i * 2 / 3. + j;
83
std::cout <<
"Computed dummy value: "
<<
v
<< std::endl;
84
85
double
t1
=
vpTime::measureTimeMs
();
86
vpTime::wait
(t1, 40);
87
88
double
t2 =
vpTime::measureTimeMs
();
89
90
// Sleep 10ms
91
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
// UNIX
92
usleep(10 * 1000);
93
#elif defined(_WIN32)
94
Sleep(10);
95
#endif
96
97
double
t3 =
vpTime::measureTimeMs
();
98
99
// Sleep 2ms
100
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
// UNIX
101
usleep(2 * 1000);
102
#elif defined(_WIN32)
103
Sleep(2);
104
#endif
105
double
t4 =
vpTime::measureTimeMs
();
106
107
vpTime::wait
(t4, 19);
108
109
double
t5 =
vpTime::measureTimeMs
();
110
111
vpTime::wait
(5);
112
113
vpChrono
chrono;
114
chrono.
start
();
115
double
t6 =
vpTime::measureTimeMs
();
116
117
vpTime::wait
(21);
118
119
chrono.
stop
();
120
chrono.
start
(
false
);
121
double
t7 =
vpTime::measureTimeMs
();
122
123
vpTime::wait
(2);
124
125
double
t8 =
vpTime::measureTimeMs
();
126
chrono.
stop
();
127
128
std::cout <<
"t1-t0: computation time: "
<<
t1
- t0 << std::endl;
129
130
std::cout <<
"t2-t1: wait(t1, 40 ms): "
<< t2 -
t1
<< std::endl;
131
std::cout <<
"t3-t2: sleep(10 ms): "
<< t3 - t2 << std::endl;
132
std::cout <<
"t4-t3: sleep(2 ms): "
<< t4 - t3 << std::endl;
133
std::cout <<
"t5-t4: wait(t, 19 ms): "
<< t5 - t4 << std::endl;
134
std::cout <<
"t6-t5: wait(5 ms): "
<< t6 - t5 << std::endl;
135
std::cout <<
"t7-t6: wait(21 ms): "
<< t7 - t6 << std::endl;
136
std::cout <<
"t8-t7: wait(2 ms): "
<< t8 - t7 << std::endl;
137
std::cout <<
"t8-t6: ; chrono: "
<< chrono.
getDurationMs
() << std::endl;
138
139
return
EXIT_SUCCESS;
140
}
141
catch
(
const
vpException
&e) {
142
std::cout <<
"Catch an exception: "
<<
e
<< std::endl;
143
return
EXIT_FAILURE;
144
}
145
#else
146
std::cout <<
"vpTime is not implemented on Universal Windows Platform"
<< std::endl;
147
#endif
148
}
vpChrono
Definition
vpTime.h:90
vpChrono::start
void start(bool reset=true)
Definition
vpTime.cpp:411
vpChrono::stop
void stop()
Definition
vpTime.cpp:426
vpChrono::getDurationMs
double getDurationMs()
Definition
vpTime.cpp:400
vpException
error that can be emitted by ViSP classes.
Definition
vpException.h:60
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
ibvs-four-points.v
v
Definition
ibvs-four-points.py:271
ibvs-four-points.e
e
Definition
ibvs-four-points.py:272
realsense-rbt.t1
t1
Definition
realsense-rbt.py:214
vpTime::measureTimeMs
VISP_EXPORT double measureTimeMs()
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
yolo-centering-task-afma6.j
j
Definition
yolo-centering-task-afma6.py:329
yolo-centering-task-afma6.i
i
Definition
yolo-centering-task-afma6.py:329
modules
core
test
tools
time
testTime.cpp
Generated by
1.17.0