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
17void test(double total_sleep, double call_sleep)
18{
19 double start_time = TMFE::GetTime();
20 double count = 0;
21 double incr = 0;
22
24
25 for (int i=0; i<loops; i++) {
27 count += 1.0;
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,
39 incr,
40 elapsed,
44}
45
46void test_alarm(int)
47{
48 printf("alarm!\n");
49}
50
51int main(int argc, char* argv[])
52{
55
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();
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 */
static double GetTime()
return current time in seconds, with micro-second precision
Definition tmfe.cxx:1011
static void Sleep(double sleep_time_sec)
sleep, with micro-second precision
Definition tmfe.cxx:1019
int main()
Definition hwtest.cxx:23
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
program test
Definition miniana.f:6
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
void test_alarm(int)