/* Find number of cycles taken by function. Do this by running number of trials until best two within TOL of each other */ double measure_function(elem_fun_t f, int cnt) { /* Need to fudge fact that fcyc wants a function taking an int *, while our function takes an int */ test_funct tf = (test_funct) f; return fcyc(tf, (int *) cnt); }
/* Run f and return clocks per inner loop iteration */ double run(test_funct f, int n) { double cpi; cpi = fcyc(f, n, CLEARCACHE) / (n*n*n); checkresult(gc, n); return(cpi); }
/* * fsecs - Return the running time of a function f (in seconds) */ double fsecs(fsecs_test_funct f, void *argp) { #if USE_FCYC double cycles = fcyc(f, argp); return cycles/(Mhz*1e6); #elif USE_ITIMER return ftimer_itimer(f, argp, 10); #elif USE_GETTOD return ftimer_gettod(f, argp, 10); #endif }
/* Perform test of combinition function */ static void run_test(lower_t lf, int len) { double time; double tpe; current_lf = lf; setup(len); current_lf(data); time = fcyc(run, NULL) / mhz(0) * 1e-6; tpe = time * 1e6 /(double) len; /* print results */ printf("%d\t%f\t%f\n", len, time, tpe); }
/* Perform test of combination function */ static void run_test(int bench_index, int cnt) { double cyc; char *description = benchmarks[bench_index].description; data_t good_result; current_benchmark = bench_index; setup(cnt); cyc = fcyc(run, NULL); benchmarks[bench_index].cfunct(data, &combine_result); benchmarks[bench_index].checkfunct(data, &good_result); if (combine_result != good_result) { printf("Function %s, Should be %d, Got %d\n", description, (int) good_result, (int) combine_result); } /* print results */ /* Column Heading */ printf("%s %s %s:\n", DATA_NAME, OPER_NAME, description); printf("%.1f cycles, Net: %.2f cycles/element\n", cyc, cyc/cnt); }
int main(int argc, char *argv[]) { int info[2]; int expected; int version; char *vname[2] = {"dynamic", "static"}; double time, tpe; int nele = MAXELE; if (argc > 1) nele = atoi(argv[1]); expected = nele*(nele-1)/2; init(nele); for (version = 0; version <= 1; version++) { int sum; info[0] = 0; info[1] = version; test_list(info); sum = info[0]; time = fcyc(test_list, info); tpe = time/nele; printf("N = %d, Allocation: %s, expected=%d, got=%d, tpe=%.2f\n", nele, vname[version], expected, sum, tpe); } return 0; }
double cpt(test_funct tf, val_t num_type, val_t den_type, int use_cond) { long params[3] = { num_type, den_type, use_cond }; double t = fcyc(tf, params); return t/NELE; }
double cpt(test_funct tf, int *arg2) { double t = fcyc(tf, arg2); return t/NELE; }