annotate src/fftw-3.3.3/libbench2/report.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2001 Matteo Frigo
Chris@10 3 * Copyright (c) 2001 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21
Chris@10 22 #include "bench.h"
Chris@10 23 #include <stdio.h>
Chris@10 24 #include <stdlib.h>
Chris@10 25 #include <math.h>
Chris@10 26
Chris@10 27 void (*report)(const bench_problem *p, double *t, int st);
Chris@10 28
Chris@10 29 #undef min
Chris@10 30 #undef max /* you never know */
Chris@10 31
Chris@10 32 struct stats {
Chris@10 33 double min;
Chris@10 34 double max;
Chris@10 35 double avg;
Chris@10 36 double median;
Chris@10 37 };
Chris@10 38
Chris@10 39 static void mkstat(double *t, int st, struct stats *a)
Chris@10 40 {
Chris@10 41 int i, j;
Chris@10 42
Chris@10 43 a->min = t[0];
Chris@10 44 a->max = t[0];
Chris@10 45 a->avg = 0.0;
Chris@10 46
Chris@10 47 for (i = 0; i < st; ++i) {
Chris@10 48 if (t[i] < a->min)
Chris@10 49 a->min = t[i];
Chris@10 50 if (t[i] > a->max)
Chris@10 51 a->max = t[i];
Chris@10 52 a->avg += t[i];
Chris@10 53 }
Chris@10 54 a->avg /= (double)st;
Chris@10 55
Chris@10 56 /* compute median --- silly bubblesort algorithm */
Chris@10 57 for (i = st - 1; i > 1; --i) {
Chris@10 58 for (j = 0; j < i - 1; ++j) {
Chris@10 59 double t0, t1;
Chris@10 60 if ((t0 = t[j]) > (t1 = t[j + 1])) {
Chris@10 61 t[j] = t1;
Chris@10 62 t[j + 1] = t0;
Chris@10 63 }
Chris@10 64 }
Chris@10 65 }
Chris@10 66 a->median = t[st / 2];
Chris@10 67 }
Chris@10 68
Chris@10 69 void report_mflops(const bench_problem *p, double *t, int st)
Chris@10 70 {
Chris@10 71 struct stats s;
Chris@10 72 mkstat(t, st, &s);
Chris@10 73 ovtpvt("(%g %g %g %g)\n",
Chris@10 74 mflops(p, s.max), mflops(p, s.avg),
Chris@10 75 mflops(p, s.min), mflops(p, s.median));
Chris@10 76 }
Chris@10 77
Chris@10 78 void report_time(const bench_problem *p, double *t, int st)
Chris@10 79 {
Chris@10 80 struct stats s;
Chris@10 81 UNUSED(p);
Chris@10 82 mkstat(t, st, &s);
Chris@10 83 ovtpvt("(%g %g %g %g)\n", s.min, s.avg, s.max, s.median);
Chris@10 84 }
Chris@10 85
Chris@10 86 void report_benchmark(const bench_problem *p, double *t, int st)
Chris@10 87 {
Chris@10 88 struct stats s;
Chris@10 89 mkstat(t, st, &s);
Chris@10 90 ovtpvt("%.5g %.8g %g\n", mflops(p, s.min), s.min, p->setup_time);
Chris@10 91 }
Chris@10 92
Chris@10 93 static void sprintf_time(double x, char *buf, int buflen)
Chris@10 94 {
Chris@10 95 #ifdef HAVE_SNPRINTF
Chris@10 96 # define MY_SPRINTF(a, b) snprintf(buf, buflen, a, b)
Chris@10 97 #else
Chris@10 98 # define MY_SPRINTF(a, b) sprintf(buf, a, b)
Chris@10 99 #endif
Chris@10 100 if (x < 1.0E-6)
Chris@10 101 MY_SPRINTF("%.2f ns", x * 1.0E9);
Chris@10 102 else if (x < 1.0E-3)
Chris@10 103 MY_SPRINTF("%.2f us", x * 1.0E6);
Chris@10 104 else if (x < 1.0)
Chris@10 105 MY_SPRINTF("%.2f ms", x * 1.0E3);
Chris@10 106 else
Chris@10 107 MY_SPRINTF("%.2f s", x);
Chris@10 108 #undef MY_SPRINTF
Chris@10 109 }
Chris@10 110
Chris@10 111 void report_verbose(const bench_problem *p, double *t, int st)
Chris@10 112 {
Chris@10 113 struct stats s;
Chris@10 114 char bmin[64], bmax[64], bavg[64], bmedian[64], btmin[64];
Chris@10 115 char bsetup[64];
Chris@10 116 int copyp = tensor_sz(p->sz) == 1;
Chris@10 117
Chris@10 118 mkstat(t, st, &s);
Chris@10 119
Chris@10 120 sprintf_time(s.min, bmin, 64);
Chris@10 121 sprintf_time(s.max, bmax, 64);
Chris@10 122 sprintf_time(s.avg, bavg, 64);
Chris@10 123 sprintf_time(s.median, bmedian, 64);
Chris@10 124 sprintf_time(time_min, btmin, 64);
Chris@10 125 sprintf_time(p->setup_time, bsetup, 64);
Chris@10 126
Chris@10 127 ovtpvt("Problem: %s, setup: %s, time: %s, %s: %.5g\n",
Chris@10 128 p->pstring, bsetup, bmin,
Chris@10 129 copyp ? "fp-move/us" : "``mflops''",
Chris@10 130 mflops(p, s.min));
Chris@10 131
Chris@10 132 if (verbose) {
Chris@10 133 ovtpvt("Took %d measurements for at least %s each.\n", st, btmin);
Chris@10 134 ovtpvt("Time: min %s, max %s, avg %s, median %s\n",
Chris@10 135 bmin, bmax, bavg, bmedian);
Chris@10 136 }
Chris@10 137 }