comparison src/fftw-3.3.3/libbench2/speed.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2001 Matteo Frigo
3 * Copyright (c) 2001 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21
22 #include "bench.h"
23
24 int no_speed_allocation = 0; /* 1 to not allocate array data in speed() */
25
26 void speed(const char *param, int setup_only)
27 {
28 double *t;
29 int iter = 0, k;
30 bench_problem *p;
31 double tmin, y;
32
33 t = (double *) bench_malloc(time_repeat * sizeof(double));
34
35 for (k = 0; k < time_repeat; ++k)
36 t[k] = 0;
37
38 p = problem_parse(param);
39 BENCH_ASSERT(can_do(p));
40 if (!no_speed_allocation) {
41 problem_alloc(p);
42 problem_zero(p);
43 }
44
45 timer_start(LIBBENCH_TIMER);
46 setup(p);
47 p->setup_time = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER));
48
49 /* reset the input to zero again, because the planner in paranoid
50 mode sets it to random values, thus making the benchmark
51 diverge. */
52 if (!no_speed_allocation)
53 problem_zero(p);
54
55 if (setup_only)
56 goto done;
57
58 start_over:
59 for (iter = 1; iter < (1<<30); iter *= 2) {
60 tmin = 1.0e20;
61 for (k = 0; k < time_repeat; ++k) {
62 timer_start(LIBBENCH_TIMER);
63 doit(iter, p);
64 y = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER));
65 if (y < 0) /* yes, it happens */
66 goto start_over;
67 t[k] = y;
68 if (y < tmin)
69 tmin = y;
70 }
71
72 if (tmin >= time_min)
73 goto done;
74 }
75
76 goto start_over; /* this also happens */
77
78 done:
79 done(p);
80
81 if (iter)
82 for (k = 0; k < time_repeat; ++k)
83 t[k] /= iter;
84 else
85 for (k = 0; k < time_repeat; ++k)
86 t[k] = 0;
87
88 report(p, t, time_repeat);
89
90 if (!no_speed_allocation)
91 problem_destroy(p);
92 bench_free(t);
93 return;
94 }