double bash( char *region, long nbytes, /* size of region to bash (bytes) */ long stride, /* stride through region (bytes) */ long iters /* target # of loop iterations */ ) { signed long count; signed long reps; clock_t start, stop; double utime, stime; count = ((nbytes - sizeof(int)) / stride) + 1; if (! (((count - 1) * stride + sizeof(int)) <= nbytes)) { fprintf(stderr, "trip count problem\n"); exit(1); } reps = (iters + count - 1) / count; if (reps <= 0) reps = 1; iters = reps * count; /* make sure the memory is allocated */ memset(region, 0, nbytes); memset(region, 1, nbytes); allocate_memory(region, nbytes); memset(region, 0, nbytes); /* warm up the cache */ (void) bash_loop(region, count, stride, 1L); /* run the bash loop */ start = clock(); (void) bash_loop(region, count, stride, reps); stop = clock(); utime = (double) (stop - start) / CLOCKS_PER_SEC; stime = 0.0; return 1e9 * ((utime + stime) / iters); }
int main() { return bash_loop(); }