MIDAS
Loading...
Searching...
No Matches
test_sleep.cxx
Go to the documentation of this file.
1
//
2
// test_sleep.cxx
3
//
4
// Test the sleep function
5
//
6
7
#include <stdio.h>
8
#include <signal.h>
// SIGPIPE
9
#include <unistd.h>
// alarm()
10
//#include <assert.h> // assert()
11
//#include <stdlib.h> // malloc()
12
//#include <math.h> // M_PI
13
14
//#include "midas.h"
15
#include "
tmfe.h
"
16
17
void
test
(
double
total_sleep,
double
call_sleep)
18
{
19
double
start_time =
TMFE::GetTime
();
20
double
count
= 0;
21
double
incr = 0;
22
23
int
loops = total_sleep/call_sleep;
24
25
for
(
int
i
=0;
i
<loops;
i
++) {
26
TMFE::Sleep
(call_sleep);
27
count
+= 1.0;
28
incr += call_sleep;
29
}
30
31
double
end_time =
TMFE::GetTime
();
32
33
double
elapsed = end_time - start_time;
34
double
actual_sleep = elapsed/
count
;
35
36
printf(
"sleep %7.0f loops, %12.3f usec per loop, %12.9f sec total, %12.9f sec actual total, %12.3f usec actual per loop, oversleep %8.3f usec, %6.1f%%\n"
,
37
count
,
38
call_sleep*1e6,
39
incr,
40
elapsed,
41
actual_sleep*1e6,
42
(actual_sleep - call_sleep)*1e6,
43
(actual_sleep - call_sleep)/call_sleep*100.0);
44
}
45
46
void
test_alarm
(
int
)
47
{
48
printf(
"alarm!\n"
);
49
}
50
51
int
main
(
int
argc,
char
* argv[])
52
{
53
setbuf(stdout, NULL);
54
setbuf(stderr, NULL);
55
56
signal(SIGPIPE, SIG_IGN);
57
signal(SIGALRM,
test_alarm
);
58
59
//TMFE::Sleep(-1.0);
60
//TMFE::Sleep(-0.0);
61
//TMFE::Sleep(+0.0);
62
//TMFE::Sleep(0);
63
//TMFE::Sleep(12345678901234567890.0);
64
65
//::alarm(2);
66
67
//TMFE* mfe = TMFE::Instance();
68
69
if
(1) {
70
printf(
"test short sleep:\n"
);
71
72
test
(1.0, 0.1);
73
test
(1.0, 0.01);
74
test
(1.0, 0.001);
75
test
(1.0, 0.0001);
76
test
(1.0, 0.00001);
77
test
(1.0, 0.000001);
78
test
(0.1, 0.0000001);
79
test
(0.01, 0.00000001);
80
}
81
82
if
(1) {
83
double
sleep_requested = 2.1*60;
// 2.1 minutes
84
printf(
"test long sleep: requested %.9f sec ... sleeping ...\n"
, sleep_requested);
85
::alarm(10);
86
double
t0 =
TMFE::GetTime
();
87
TMFE::Sleep
(sleep_requested);
88
double
t1 =
TMFE::GetTime
();
89
double
sleep_actual = t1 - t0;
90
printf(
"test long sleep: requested %.9f sec, actual %.9f sec\n"
, sleep_requested, sleep_actual);
91
}
92
93
return
0;
94
}
95
96
/* emacs
97
* Local Variables:
98
* tab-width: 8
99
* c-basic-offset: 3
100
* indent-tabs-mode: nil
101
* End:
102
*/
TMFE::GetTime
static double GetTime()
return current time in seconds, with micro-second precision
Definition
tmfe.cxx:1011
TMFE::Sleep
static void Sleep(double sleep_time_sec)
sleep, with micro-second precision
Definition
tmfe.cxx:1019
main
int main()
Definition
hwtest.cxx:23
count
double count
Definition
mdump.cxx:33
i
INT i
Definition
mdump.cxx:32
test
program test
Definition
miniana.f:6
test_alarm
void test_alarm(int)
Definition
test_sleep.cxx:46
tmfe.h
progs
test_sleep.cxx
Generated on Sat Dec 6 2025 05:01:07 for MIDAS by
1.9.8