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