. use library function to parse memory string
[minix3.git] / test / select / speed.c
blob889d3a4c86742ea0206fe310f5d938d8c02354b6
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 void main(void) {
28 char *udp_device;
29 int fd[NUMBER];
30 fd_set fds_write;
31 struct timeval timeout;
32 time_t start_time, end_time;
33 int i;
35 FD_ZERO(&fds_write);
36 for (i = 0; i < NUMBER; i++) {
37 fd[i] = open("/dev/tty", O_RDWR);
38 if (fd[i] < 0) {
39 fprintf(stderr, "Error opening tty %d\n", i);
40 exit(-1);
42 FD_SET(fd[i], &fds_write);
45 printf("Select will send 1 msg to terminal and %d to inet: \n", NUMBER);
46 timeout.tv_sec = 0;
47 timeout.tv_usec = 0;
48 /* get initial time */
49 start_time = time(NULL);
50 for (i = 0; i < 32000; i++) {
51 select(NUMBER + 4, NULL, &fds_write, NULL, &timeout);
53 /* get final time */
54 end_time = time(NULL);
55 printf("The select call took on average: %f\n", (float)(end_time - start_time) / 32000.0);
56 for (i = 0; i < NUMBER; i++) {
57 close(fd[i]);