home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/timeb.h>
- #include <sys/stat.h>
-
- struct timeb timebuffer1;
- struct timeb timebuffer2;
-
- #define BSIZE 8192
- char buf[BSIZE];
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- int fh;
- int n;
- int i;
- long total = 0;
- long sec;
- long msec;
- long bpmsec;
- int res;
- if(argc != 3 || (n = atoi(argv[2])) == 0 ) {
- printf("usage: %s filename nblks\n", argv[0]);
- exit(1);
- }
-
- fh = open(argv[1], O_CREAT|O_WRONLY|O_BINARY, S_IWRITE|S_IREAD);
- if(fh < 0) {
- perror("open:");
- exit(1);
- }
- ftime(&timebuffer1);
- for (i = 0; i < n; i++) {
- if((res = write(fh, buf, BSIZE)) != BSIZE) {
- if(res < 0)
- perror("write:");
- else
- printf("out of space\n");
- exit(1);
- }
- total += res;
- }
- ftime(&timebuffer2);
- close(fh);
-
- sec = timebuffer2.time - timebuffer1.time;
- msec = (long)timebuffer2.millitm - (long)timebuffer1.millitm;
- if(msec < 0) {
- sec -= 1;
- msec += 1000;
- }
- msec = sec*1000 + msec;
- bpmsec = (msec == 0 ? 0 : total/msec);
- printf("total time %ld msec total bytes %ld bytes/msec %ld\n",
- msec, total, bpmsec);
- exit(0);
- }
-