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