From: geoff@tyger.Eng.Sun.COM (Geoff Arnold @ Sun BOS - R.H. coast near the top)
Newsgroups: comp.protocols.nfs
Subject: Re: Sun PC-NFS performance (again)
Date: 15 Dec 1992 15:13:08 GMT
Organization: SunSelect
NNTP-Posting-Host: tyger.east.sun.com

Here are the reader and writer programs that I mentioned in my last
posting. unix2dos 'em and compile - I used MSC 6.0a.

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh to create the files:
#	reader.c
#	writer.c
# This archive created: Tue Dec 15 08:26:45 1992 by geoff, SunSelect
#
#
export PATH; PATH=/bin:$PATH


if test -f reader.c ; then
echo shar: will not over-write existing file reader.c
else
echo shar: extracting reader.c, 1102 characters
sed 's/^X//' > reader.c <<'SHAR_EOF'
X#include <stdio.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/timeb.h>
X
Xstruct timeb timebuffer1;
Xstruct timeb timebuffer2;
X
X#define BSIZE 8192
Xchar buf[BSIZE];
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
Xint fh;
Xlong total = 0;
Xlong sec;
Xlong msec;
Xlong bpmsec;
Xint res;
Xif(argc != 2) {
X        printf("usage: %s filename\n", argv[0]);
X        exit(1);
X}
X
Xfh = open(argv[1], O_RDONLY|O_BINARY);
Xif(fh < 0) {
X        perror("open:");
X        exit(1);
X}
Xftime(&timebuffer1);
Xwhile((res = read(fh, buf, BSIZE)) > 0) total += res;
Xif(res < 0) {
X        perror("read:");
X        exit(1);
X}
Xftime(&timebuffer2);
Xclose(fh);
Xprintf("stop  %10ld.%03d\n", timebuffer2.time, timebuffer2.millitm);
Xprintf("start %10ld.%03d\n", timebuffer1.time, timebuffer1.millitm);
X
Xsec = timebuffer2.time - timebuffer1.time;
Xmsec = (long)timebuffer2.millitm - (long)timebuffer1.millitm;
Xif(msec < 0) {
X        sec -= 1;
X        msec += 1000;
X}
Xmsec = sec*1000 + msec;
Xbpmsec = (msec == 0 ? 0 : total/msec);
Xprintf("total time %ld msec   total bytes %ld   bytes/msec %ld\n",
X        msec, total, bpmsec);
Xexit(0);
X}
SHAR_EOF
len=`wc -c < reader.c`
if test $len != 1102 ; then
echo shar: reader.c was $len bytes long, should have been 1102
fi
fi # end of overwriting check

if test -f writer.c ; then
echo shar: will not over-write existing file writer.c
else
echo shar: extracting writer.c, 1228 characters
sed 's/^X//' > writer.c <<'SHAR_EOF'
X#include <stdio.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/timeb.h>
X#include <sys/stat.h>
X
Xstruct timeb timebuffer1;
Xstruct timeb timebuffer2;
X
X#define BSIZE 8192
Xchar buf[BSIZE];
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
Xint fh;
Xint n;
Xint i;
Xlong total = 0;
Xlong sec;
Xlong msec;
Xlong bpmsec;
Xint res;
Xif(argc != 3 || (n = atoi(argv[2])) == 0 ) {
X        printf("usage: %s filename nblks\n", argv[0]);
X        exit(1);
X}
X
Xfh = open(argv[1], O_CREAT|O_WRONLY|O_BINARY, S_IWRITE|S_IREAD);
Xif(fh < 0) {
X        perror("open:");
X        exit(1);
X}
Xftime(&timebuffer1);
Xfor (i = 0; i < n; i++) {
X        if((res = write(fh, buf, BSIZE)) != BSIZE) {
X                if(res < 0)
X                        perror("write:");
X                else
X                        printf("out of space\n");
X                exit(1);
X        }
X        total += res;
X}
Xftime(&timebuffer2);
Xclose(fh);
X
Xsec = timebuffer2.time - timebuffer1.time;
Xmsec = (long)timebuffer2.millitm - (long)timebuffer1.millitm;
Xif(msec < 0) {
X        sec -= 1;
X        msec += 1000;
X}
Xmsec = sec*1000 + msec;
Xbpmsec = (msec == 0 ? 0 : total/msec);
Xprintf("total time %ld msec   total bytes %ld   bytes/msec %ld\n",
X        msec, total, bpmsec);
Xexit(0);
X}
SHAR_EOF
len=`wc -c < writer.c`
if test $len != 1228 ; then
echo shar: writer.c was $len bytes long, should have been 1228
fi
fi # end of overwriting check

exit 0
#	End of shell archive
--
Geoff Arnold, PC-NFS architect, Sun Select. (geoff.arnold@East.Sun.COM)
ADMINISTRIVIA==========ADMINISTRIVIA=====ADMINISTRIVIA==========ADMINISTRIVIA
New address: SunSelect, 2 Elizabeth Drive, Chelmsford, MA 01824-4195
New numbers: Phone: 508-442-0317   FAX: 508-250-5068