annotate src/fftw-3.3.5/libbench2/report.c @ 84:08ae793730bd

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