home *** CD-ROM | disk | FTP | other *** search
- /*
- * "IO Zone" Benchmark Program
- *
- * Author: Bill Norcott (Bill.Norcott@nuo.mts.dec.com)
- * 4 Dunlap Drive
- * Nashua, NH 03060
- *
- * "Copyright 1991, William D. Norcott
- * This is free software. License to freely use and distribute this
- * software is hereby granted by the author, subject to the condition
- * that this copyright notice remains intact."
- *
- * "This test writes a 4 MEGABYTE sequential file in 512 byte chunks, then
- * rewinds it and reads it back. [The size of the file should be
- * big enough to factor out the effect of any disk cache.]
- *
- * The file is written (filling any cache buffers), and then read. If the
- * cache is >= 4 MB, then most if not all the reads will be satisfied from
- * the cache. However, if it is less than or equal to 2 MB, then NONE of
- * the reads will be satisfied from the cache. This is becase after the
- * file is written, a 2 MB cache will contain the upper 2 MB of the test
- * file, but we will start reading from the beginning of the file (data
- * which is no longer in the cache)
- * In order for this to be a fair test, the length of the test file must
- * be AT LEAST 2X the amount of disk cache memory for your system. If
- * not, you are really testing the speed at which your CPU can read blocks
- * out of the cache (not a fair test)
- *
- * IOZONE does NOT test the raw I/O speed of your disk or system. It
- * tests the speed of sequential I/O to actual files. Therefore, this
- * measurement factors in the efficiency of you machines file system,
- * operating system, C compiler, and C runtime library. It produces a
- * measurement which is the number of bytes per second that your system
- * can read or write to a file. For UNIX systems I call fsync() to force
- * the writes to disk. This gives a test of the time it takes to
- * actually get data onto the disk.
- *
- * This program has been ported and tested on the following computer
- * operating systems:
- * VAX/VMS V5.4, Ultrix V4.1, OSF/1 and MS-DOS 3.3"
- *
- * --- MODIFICATION HISTORY:
- *
- * 3/7/91 William D. Norcott (Bill.Norcott@nuo.mts.dec.com)
- * created
- * 3/22/91 Bill Norcott tested on OSF/1 ... it works
- *
- */
- #ifdef __MSDOS__ /* Turbo C define this way for PCs... */
- #define MSDOS /* Microsoft C defines this */
- #endif
- /* VMS and MS-DOS both have ANSI C compilers and use rand()/srand() */
- #ifdef VMS_POSIX
- #undef VMS
- #define ANSI_RANDOM 1
- #endif
- #ifdef MSDOS
- #define ANSI_RANDOM 1
- #endif
-
- #if defined(VMS)
- #define ANSI_RANDOM 1
- #include <math.h>
- #include <unixio.h>
- #include <ssdef.h>
- #include <file.h>
-
- #elif defined(MSDOS)
- #include <fcntl.h>
- #elif defined(unix)
- #include <sys/file.h>
- #include <limits.h>
- #endif
-
- #define MEGABYTES 1 /* number of megabytes in file */
- #define RECLEN 512 /* number of bytes in a record */
- #define FILESIZE (MEGABYTES*1024*1024) /*size of file in bytes*/
- #define NUMRECS FILESIZE/RECLEN /* number of records */
- #define MAXBUFFERSIZE 16*1024 /*maximum buffer size*/
- #define TOOFAST 10
- #define USAGE "\tUsage:\tiozone [megabytes] [record_length] [[path]filename]\n\n"
- #define THISVERSION "V1.01"
-
- /* Define only one of the following two.*/
- /*#define NOTIME define if no time function in library*/
- #define TIME /*Use time(2)function*/
-
- #define MAXNAMESIZE 1000 /* max # of characters in filename */
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int fd;
- char filename [MAXNAMESIZE]; /* name of temporary file */
- #ifdef VMS
- char *default_filename="iozone_temp_file"; /*default name of temporary file*/
- #else
- #ifdef MSDOS
- char *default_filename="iozone.tmp"; /*default name of temporary file*/
- #else
- char *default_filename="/tmp/iozone_temp_file"; /*default name of temporary file*/
- #endif
- #endif
- #ifdef MSDOS
- char *buffer;
- #else
- char buffer [MAXBUFFERSIZE]; /*a temporary data buffer*/
- #endif
- int i, status;
- unsigned long megabytes = MEGABYTES, goodmegs;
- unsigned long reclen = RECLEN, goodrecl;
- unsigned long filesize = FILESIZE;
- unsigned long numrecs = NUMRECS;
-
- #ifdef TIME
- long time();
- long starttime1, starttime2;
- long writetime;
- long totaltime;
-
- #endif
-
- #ifdef MSDOS
- buffer = (char *) malloc(MAXBUFFERSIZE);
- #endif
-
- printf("\n\tIOZONE: Performance Test of Sequential File I/O -- %s\n",
- THISVERSION);
- printf("\t\tBy Bill Norcott\n\n");
-
- strcpy(filename,default_filename);
- switch (argc) {
- case 1: /* no args, take all defaults */
- printf(USAGE);
- break;
- case 2: /* <megabytes|filename> */
- i = atoi(argv[1]); if (i) {
- megabytes = i;
- } else {
- strcpy(filename,argv[1]);
- }
- break;
- case 3: /* <megabytes> <reclen|filename> */
- filesize = atoi(argv[1]);
- i = atoi(argv[2]); if(i) {
- reclen = (unsigned) i;
- } else {
- strcpy(filename,argv[2]);
- }
- break;
- case 4: /* <megabytes> <reclen> <filename> */
- filesize = atoi(argv[1]);
- reclen = atoi(argv[2]);
- strcpy(filename,argv[3]);
- break;
- default:
- printf(USAGE);
- exit(1);
-
- }
- printf("\tSend comments to:\tBill.Norcott@nuo.mts.dec.com\n\n");
-
- filesize = megabytes*1024*1024;
- numrecs = filesize/reclen;
- if (reclen > MAXBUFFERSIZE) {
- printf("Error: Maximum record length is %d bytes\n", MAXBUFFERSIZE);
- }
- printf("\tIOZONE writes a %ld Megabyte sequential file consisting of\n",
- megabytes);
- printf("\t%ld records which are each %ld bytes in length.\n",
- numrecs, reclen);
- printf("\tIt then reads the file. It prints the bytes-per-second\n");
- printf("\trate at which the computer can read and write files.\n\n");
- printf("\nWriting the %ld Megabyte file, '%s'...", megabytes, filename);
-
- #ifdef TIME
- starttime1 = time(0);
- #endif
- if((fd = creat(filename, 0640))<0){
- printf("Cannot create temporary file\n");
- exit(1);
- }
- for(i=0; i<numrecs; i++){
- write(fd, buffer, (unsigned) reclen);
- }
-
- #ifdef TIME
- writetime = time(0) - starttime1;
- printf("%d seconds", writetime);
- #endif
- close(fd);
- #ifdef VMS
- if((fd = open(filename, O_RDONLY, 0640))<0){
- printf("Cannot open temporary file for read\n");
- exit(1);
- #elif defined(MSDOS)
- if((fd = open(filename, O_RDONLY, 0640))<0){
- printf("Cannot open temporary file for read\n");
- exit(1);
- #else
- if((fd = open(filename, O_RDONLY))<0){
- printf("Cannot open temporary file for read\n");
- exit(1);
- #endif
- }
-
- /*start timing*/
- #ifdef NOTIME
- printf("start timing\n");
- #endif
-
- printf("\nReading the file...");
- starttime2 = time(0);
- for(i=0; i<numrecs; i++) {
- if(read(fd, buffer, (unsigned) reclen) < 0)
- perror("Read error");
- }
- #ifdef NOTIME
- printf("stop timing\n");
- #endif
- #ifdef TIME
- totaltime = time(0) - starttime2;
-
- printf("%d seconds\n", totaltime);
- if(totaltime!=0)
- {
- printf("\nIOZONE performance measurements:\n");
- printf("\t%ld bytes/second for writing the file\n",
- (long) ((numrecs*reclen)/writetime) );
- printf("\t%ld bytes/second for reading the file\n",
- (long) ((numrecs*reclen)/totaltime) );
- if (totaltime < TOOFAST) {
- goodmegs = (TOOFAST/totaltime)*2*megabytes;
- printf("\nThis machine is fast (or is using a disk cache)!\n");
- printf("You will get a more accurate measure of its\n");
- printf("performance by re-running IOZONE using the command:\n");
- printf("\n\tiozone %d ", goodmegs);
- printf("\t(i.e., file size = %d megabytes)\n", goodmegs);
- }
- } else {
- goodrecl = reclen/2;
- printf("\nI/O error during read. Try again with the command:\n");
- printf("\n\tiozone %d %d ",megabytes, (int) goodrecl);
- printf("\t(i.e. record size = %d bytes)\n", (int) goodrecl);
- }
- #endif
- close(fd);
- #ifndef VMS
- unlink(filename); /* delete the file */
- /*stop timer*/
- #endif
- #ifdef MSDOS
- free(buffer); /* deallocate the memory */
- #endif
- #ifdef VMS
- return SS$_NORMAL;
- #else
- return 0;
- #endif
- }
-
-
-