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

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