4 * Objetive: Test the time it takes for select to run.
6 * Description: This tests creates a number of udp connections and performs
7 * a select call waiting on them for reading with timeout of 0.
8 * This is done 10,000 thousands of times and then the average time it takes
14 #include <sys/types.h>
17 #include <sys/select.h>
18 #include <sys/asynchio.h>
22 #include <net/netlib.h>
27 int main(int argc
, char *argv
[])
32 struct timeval timeout
;
33 time_t start_time
, end_time
;
37 for (i
= 0; i
< NUMBER
; i
++) {
38 fd
[i
] = open("/dev/tty", O_RDWR
);
40 fprintf(stderr
, "Error opening tty %d\n", i
);
43 FD_SET(fd
[i
], &fds_write
);
46 printf("Select will send 1 msg to terminal and %d to inet: \n", NUMBER
);
49 /* get initial time */
50 start_time
= time(NULL
);
51 for (i
= 0; i
< 32000; i
++) {
52 select(NUMBER
+ 4, NULL
, &fds_write
, NULL
, &timeout
);
55 end_time
= time(NULL
);
56 printf("The select call took on average: %f\n", (float)(end_time
- start_time
) / 32000.0);
57 for (i
= 0; i
< NUMBER
; i
++) {