
char * outstr = "This is a test";

#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <fcntl.h>

main()
{
	struct timeval starttime, endtime;
	char buf[128];
	int fds[2];
	int i;

	pipe(fds);
	for (i = 0; i < 4096; i++) {
		write(fds[1], "a", 1);
	}

	if (fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0) {
		printf("Bad fcntl call\n");
		exit(1);
	}

	switch (fork()) {
	case -1:
		printf("Error fork\n");
		exit(1);
		break;
	case 0:
		if (gettimeofday(&starttime, NULL)) {
      		perror ("gettimeofday");
			exit(1);
    	}
		for (i = 0; i < 4096; i++) {
			if (read(fds[0], buf, 1) < 0) {
				printf("Bad read\n");
				exit(1);
			}
		}
		if (gettimeofday(&endtime, NULL)) {
      		perror ("gettimeofday");
			exit(1);
    	}
		printf("4096 reads of a pipe took %d usecs.\n", 
          (endtime.tv_sec - starttime.tv_sec) * 1000000 +
          (endtime.tv_usec - starttime.tv_usec));
		break;
	default:
		break;
	}
	exit(0);
}
