cannam@127: /* cannam@127: * Copyright (c) 2001 Matteo Frigo cannam@127: * Copyright (c) 2001 Massachusetts Institute of Technology cannam@127: * cannam@127: * This program is free software; you can redistribute it and/or modify cannam@127: * it under the terms of the GNU General Public License as published by cannam@127: * the Free Software Foundation; either version 2 of the License, or cannam@127: * (at your option) any later version. cannam@127: * cannam@127: * This program is distributed in the hope that it will be useful, cannam@127: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@127: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@127: * GNU General Public License for more details. cannam@127: * cannam@127: * You should have received a copy of the GNU General Public License cannam@127: * along with this program; if not, write to the Free Software cannam@127: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@127: * cannam@127: */ cannam@127: cannam@127: cannam@127: #include "bench.h" cannam@127: cannam@127: int no_speed_allocation = 0; /* 1 to not allocate array data in speed() */ cannam@127: cannam@127: void speed(const char *param, int setup_only) cannam@127: { cannam@127: double *t; cannam@127: int iter = 0, k; cannam@127: bench_problem *p; cannam@127: double tmin, y; cannam@127: cannam@127: t = (double *) bench_malloc(time_repeat * sizeof(double)); cannam@127: cannam@127: for (k = 0; k < time_repeat; ++k) cannam@127: t[k] = 0; cannam@127: cannam@127: p = problem_parse(param); cannam@127: BENCH_ASSERT(can_do(p)); cannam@127: if (!no_speed_allocation) { cannam@127: problem_alloc(p); cannam@127: problem_zero(p); cannam@127: } cannam@127: cannam@127: timer_start(LIBBENCH_TIMER); cannam@127: setup(p); cannam@127: p->setup_time = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER)); cannam@127: cannam@127: /* reset the input to zero again, because the planner in paranoid cannam@127: mode sets it to random values, thus making the benchmark cannam@127: diverge. */ cannam@127: if (!no_speed_allocation) cannam@127: problem_zero(p); cannam@127: cannam@127: if (setup_only) cannam@127: goto done; cannam@127: cannam@127: start_over: cannam@127: for (iter = 1; iter < (1<<30); iter *= 2) { cannam@127: tmin = 1.0e20; cannam@127: for (k = 0; k < time_repeat; ++k) { cannam@127: timer_start(LIBBENCH_TIMER); cannam@127: doit(iter, p); cannam@127: y = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER)); cannam@127: if (y < 0) /* yes, it happens */ cannam@127: goto start_over; cannam@127: t[k] = y; cannam@127: if (y < tmin) cannam@127: tmin = y; cannam@127: } cannam@127: cannam@127: if (tmin >= time_min) cannam@127: goto done; cannam@127: } cannam@127: cannam@127: goto start_over; /* this also happens */ cannam@127: cannam@127: done: cannam@127: done(p); cannam@127: cannam@127: if (iter) cannam@127: for (k = 0; k < time_repeat; ++k) cannam@127: t[k] /= iter; cannam@127: else cannam@127: for (k = 0; k < time_repeat; ++k) cannam@127: t[k] = 0; cannam@127: cannam@127: report(p, t, time_repeat); cannam@127: cannam@127: if (!no_speed_allocation) cannam@127: problem_destroy(p); cannam@127: bench_free(t); cannam@127: return; cannam@127: }