/* * write-bench.c * * test write-performance to a device for n loops, designed for * testing to a raw device where the underlying physical device has * caching turned off * * cw@f00f.org --- Mon Jul 16 04:21:12 NZST 2001 * * USE AT YOUR OWN RISK! NO WARRANTY GIVEN OR IMPLIED */ #include #include #include #include #include #include #include /* #include */ /* XXX edit for your CPU */ const float MHz = 860.947 * 1000 * 1000; /* some kind of 64-bit tsc is required */ #ifdef __i386__ #define rdtsc(low,high) \ __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) #else /* __i386__ */ #error "Please define rdtsc(low32,high32) for your architecture" #endif /* __i386__ */ int main(int argc,char *argv[]) { const int secsize = 512; int f, i, loops; char *buf; double sum = 0.0, sumsq = 0.0, duration; union jack { unsigned int l[2]; unsigned long long v; }before_io, after_io; if(argc != 3){ fprintf(stderr,"please supply two arguments; " "the device and the number of loops\n"); return 2; } loops = atoi(argv[2]); if(!(buf = malloc(secsize))){ perror("malloc"); return 1; } if(((long)buf) % secsize){ free(buf); if(!(buf = malloc(secsize*2 - 1))){ perror("malloc"); return 1; } (long)buf = ((long)buf + secsize - 1) & ~(secsize - 1); } /* memfill(buf, secsize, "wibble", 6); */ memset(buf, 'r', secsize); if(-1 == (f = open(argv[1], O_RDWR))){ perror("open"); return 1; } rdtsc(before_io.l[0],before_io.l[1]); for(i=0;i