Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
dtime.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002 #include <unistd.h>
00003
00004 #define FNAME "Fred.Mertz"
00005
00006 int main( int argc , char * argv[] )
00007 {
00008 int nmeg , nrep , ii , jj ;
00009 char * bbb ;
00010 FILE * fp ;
00011
00012 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00013 printf("Usage: dtime meg rep\n"
00014 "Write 'meg' Mbytes of data to a file 'rep' times,\n"
00015 "and prints out the time that it takes.\n"
00016 ) ;
00017 exit(0) ;
00018 }
00019
00020 nmeg = strtol( argv[1] , NULL , 10 ) * 1024 * 1024 ;
00021 nrep = strtol( argv[2] , NULL , 10 ) ;
00022
00023 if( nmeg <= 0 || nrep <= 0 ){
00024 fprintf(stderr,"*** What are you, stupid?\n");
00025 exit(1);
00026 }
00027
00028 if( THD_is_file(FNAME) ){
00029 fprintf(stderr,"Can't execute: temporary file %s exists!\n",FNAME) ;
00030 exit(1) ;
00031 }
00032
00033 fp = fopen( FNAME , "wb" ) ;
00034
00035 bbb = (char *) malloc( nmeg ) ;
00036 for( ii=0 ; ii < nmeg ; ii++ ) bbb[ii] = ii % 128 ;
00037
00038 fprintf(stderr,"=== Initialization complete\n") ;
00039
00040 (void) COX_clock_time() ;
00041
00042 for( jj=0 ; jj < nrep ; jj++ ){
00043 fwrite( bbb , 1 , nmeg , fp ) ; fflush(fp) ; fsync(fileno(fp)) ; sync() ;
00044 fprintf(stderr,"#%03d: clock=%g\n", jj+1 , COX_clock_time() ) ;
00045 }
00046
00047 fprintf(stderr,"=== %g Mbytes/second average\n",
00048 nmeg*nrep/(1024.*1024.*COX_clock_time()) ) ;
00049
00050 fclose(fp) ; remove(FNAME) ; exit(0) ;
00051 }