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