#include #include #include #include #include // memdance.c by Tyler Bletsch (Tyler.Bletsch@duke.edu) for ECE250 // Benchmark the rate of basically random memory access to a block of memory for a given amount of a time const int ACCESSES_PER_STEP = 1000000; // needs to be big enough that most of the time is spent hitting memory rather than computing time of day const int IDX_DELTA = 60029; // a fairly big prime so it won't wrap neatly for any common work size // settings to use in default mode const size_t DEFAULT_SIZES[] = {1*1024*1024, 2*1024*1024, 4*1024*1024, 8*1024*1024, 16*1024*1024, 32*1024*1024, 64*1024*1024, 128*1024*1024}; const int NUM_DEFAULT_SIZES = sizeof(DEFAULT_SIZES)/sizeof(*DEFAULT_SIZES); const int DEFAULT_EXECUTION_TIME = 3; // get current time as a double double get_time() { struct timeval tv; gettimeofday(&tv, NULL); return (double)tv.tv_sec + tv.tv_usec/1000000.0;; } // run one test with the buffer size and runtime chosen; print resulting stats void run_test(size_t buffer_size, int execution_time) { int steps = 0; // our counter double time_start = get_time(); char* buf = (char*) malloc(buffer_size); int idx = 0; // outer loop: keep going until we're out of time while (get_time() < time_start+execution_time) { // inner loop: do a bunch of accesses as fast as possible // this inner loop is here so the overhead of determining the time doesn't significantly affect our measurement for (int s=0; s \n",argv[0]); return 1; } }