annotate fft/fftw/fftw-3.3.4/libbench2/report.c @ 40:223f770b5341 kissfft-double tip

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