t40c term[] count fix
[minix.git] / test / select / speed.c
blob46956b1812b97a4157e30c0d4d6ebd7089a21395
1 /*
2 * Test name: speed.c
4 * Objetive: Test the time it takes for select to run.
5 *
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
9 * is computed
11 * Jose M. Gomez
14 #include <sys/types.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/select.h>
18 #include <sys/asynchio.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <limits.h>
22 #include <net/netlib.h>
23 #include <time.h>
25 #define NUMBER 12
27 int main(int argc, char *argv[])
29 char *udp_device;
30 int fd[NUMBER];
31 fd_set fds_write;
32 struct timeval timeout;
33 time_t start_time, end_time;
34 int i;
36 FD_ZERO(&fds_write);
37 for (i = 0; i < NUMBER; i++) {
38 fd[i] = open("/dev/tty", O_RDWR);
39 if (fd[i] < 0) {
40 fprintf(stderr, "Error opening tty %d\n", i);
41 exit(-1);
43 FD_SET(fd[i], &fds_write);
46 printf("Select will send 1 msg to terminal and %d to inet: \n", NUMBER);
47 timeout.tv_sec = 0;
48 timeout.tv_usec = 0;
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);
54 /* get final time */
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++) {
58 close(fd[i]);
60 return 0;