3 * Demonstration of standalone benchmarking
5 * (c) 2024 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU Library General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * mLib is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 * License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 /*----- Header files ------------------------------------------------------*/
36 #include "tvec-adhoc.h"
37 #include "tvec-bench.h"
38 #include "tvec-types.h"
42 /*----- Macro from the manpage --------------------------------------------*/
44 #define BENCHMARK_DECLS \
45 struct bench_timing _bmark_t; \
49 #define BENCHMARK_TAG(tag, b, unit, base) \
50 MC_BEFORE(tag##__benchmark_before, { fflush(stdout); }) \
51 MC_AFTER(tag##__benchmark_after, { \
55 fputs(": ", stdout); \
56 bench_report(&file_printops, stdout, (unit), &_bmark_t); \
60 BENCH_MEASURE_TAG(tag##__benchmark_measure, \
61 (b), _bmark_rc, &_bmark_t, (base))
62 #define BENCHMARK(b, unit, base) BENCHMARK_TAG(bench, b, unit, base)
64 /*----- Main code ---------------------------------------------------------*/
71 if (bench_init(&b, 0))
72 { fprintf(stderr, "timer setup failed\n"); exit(2); }
73 if (bench_calibrate(&b, 0))
74 { fprintf(stderr, "timer calibration failed\n"); exit(2); }
76 printf("recfib, n = %u", RECFIBLIMIT);
77 BENCHMARK(&b, BTU_OP, 1)
78 while (_bench_n--) ADMIRE(recfib(RECFIBLIMIT));
80 printf("iterfib, n = %u", FIBLIMIT);
81 BENCHMARK(&b, BTU_OP, 1)
82 while (_bench_n--) ADMIRE(iterfib(FIBLIMIT));
84 printf("expfib, n = %u", FIBLIMIT);
85 BENCHMARK(&b, BTU_OP, 1)
86 while (_bench_n--) ADMIRE(expfib(FIBLIMIT));
91 /*----- That's all, folks -------------------------------------------------*/