#include #include #include #include #include int main(argc,argv) int argc; char *argv[]; { register unsigned i,j,n; unsigned *buf; unsigned bsz,stp; clock_t rstart,rend,cstart,cend,istart,iend; struct tms tm; char *pname; double srun,sela,crun,cela,cper,scre; long clk_tck=sysconf(_SC_CLK_TCK); istart=times(&tm); if(pname=rindex(argv[0],'/')) pname++; else pname=argv[0]; printf("%s - Eric's memory/cache benchmark v2.0\n",pname); if(argc!=3){ fprintf(stderr,"Usage: %s size steps\n\n" "where size is the size of the memory buffer to allocate and\n" "steps is the number of memory accesses to make.\n",pname); exit(1); } bsz=atoi(argv[1]); stp=atoi(argv[2]); printf( "Performing test: size=%d, steps=%d, sizeof(int)=%d...", bsz,stp,sizeof(int)); if(!(buf=calloc(bsz,sizeof(int)))){ fprintf(stderr,"Memory allocation of integer array failed!\n"); exit(2); } for(i=0;i