1 /*******************************************************************************
2  *  The BYTE UNIX Benchmarks - Release 3
3  *          Module: pipe.c   SID: 3.3 5/15/91 19:30:20
4  *
5  *******************************************************************************
6  * Bug reports, patches, comments, suggestions should be sent to:
7  *
8  *	Ben Smith, Rick Grehan or Tom Yager
9  *	ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
10  *
11  *******************************************************************************
12  *  Modification Log:
13  *  $Header: pipe.c,v 3.5 87/06/22 14:32:36 kjmcdonell Beta $
14  *  August 29, 1990 - modified timing routines (ty)
15  *  October 22, 1997 - code cleanup to remove ANSI C compiler warnings
16  *                     Andy Kahn <kahn@zk3.dec.com>
17  *
18  ******************************************************************************/
19 char SCCSid[] = "@(#) @(#)pipe.c:3.3 -- 5/15/91 19:30:20";
20 /*
21  *  pipe  -- test single process pipe throughput (no context switching)
22  *
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <errno.h>
28 #include "timeit.c"
29 
30 unsigned long iter;
31 
report()32 void report()
33 {
34 	fprintf(stderr,"COUNT|%ld|1|lps\n", iter);
35 	exit(0);
36 }
37 
main(argc,argv)38 int main(argc, argv)
39 int	argc;
40 char	*argv[];
41 {
42 	char	buf[512];
43 	int		pvec[2], duration;
44 
45 	if (argc != 2) {
46 		fprintf(stderr,"Usage: %s duration\n", argv[0]);
47 		exit(1);
48 		}
49 
50 	duration = atoi(argv[1]);
51 
52 	pipe(pvec);
53 
54 	wake_me(duration, report);
55 	iter = 0;
56 
57 	while (1) {
58 		if (write(pvec[1], buf, sizeof(buf)) != sizeof(buf)) {
59 			if ((errno != EINTR) && (errno != 0))
60 				fprintf(stderr,"write failed, error %d\n", errno);
61 			}
62 		if (read(pvec[0], buf, sizeof(buf)) != sizeof(buf)) {
63 			if ((errno != EINTR) && (errno != 0))
64 				fprintf(stderr,"read failed, error %d\n", errno);
65 			}
66 		iter++;
67 	}
68 }
69