#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "tmfe.h"
Go to the source code of this file.
|
| void | test (double total_sleep, double call_sleep) |
| |
| void | test_alarm (int) |
| |
| int | main (int argc, char *argv[]) |
| |
◆ main()
| int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
Definition at line 51 of file test_sleep.cxx.
52{
53 setbuf(stdout, NULL);
54 setbuf(stderr, NULL);
55
56 signal(SIGPIPE, SIG_IGN);
58
59
60
61
62
63
64
65
66
67
68
69 if (1) {
70 printf("test short sleep:\n");
71
79 test(0.01, 0.00000001);
80 }
81
82 if (1) {
83 double sleep_requested = 2.1*60;
84 printf("test long sleep: requested %.9f sec ... sleeping ...\n", sleep_requested);
85 ::alarm(10);
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}
static double GetTime()
return current time in seconds, with micro-second precision
static void Sleep(double sleep_time_sec)
sleep, with micro-second precision
◆ test()
| void test |
( |
double |
total_sleep, |
|
|
double |
call_sleep |
|
) |
| |
Definition at line 17 of file test_sleep.cxx.
18{
21 double incr = 0;
22
23 int loops = total_sleep/call_sleep;
24
25 for (
int i=0;
i<loops;
i++) {
28 incr += call_sleep;
29 }
30
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",
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}
◆ test_alarm()