source: trunk/minix/test/select/speed.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.3 KB
RevLine 
[9]1/*
2 * Test name: speed.c
3 *
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
10 *
11 * Jose M. Gomez
12 */
13
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>
24
25#define NUMBER 12
26
27void 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;
34
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);
41 }
42 FD_SET(fd[i], &fds_write);
43 }
44
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);
52 }
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]);
58 }
59}
Note: See TracBrowser for help on using the repository browser.