chiark / gitweb /
@@@ more mess
[mLib] / test / example / adhoc.c
1 /* -*-c-*-
2  *
3  * Demonstration of ad-doc testing
4  *
5  * (c) 2024 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
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.
16  *
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.
21  *
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,
25  * USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include <stdio.h>
31
32 #include "macros.h"
33 #include "report.h"
34 #include "tvec.h"
35 #include "tvec-adhoc.h"
36 #include "tvec-bench.h"
37 #include "tvec-types.h"
38
39 #include "example.h"
40
41 /*----- Main code ---------------------------------------------------------*/
42
43 int main(int argc, char *argv[])
44 {
45   struct tvec_state tvstate;
46   int argpos;
47   unsigned long i, a, b, t;
48   dstr d = DSTR_INIT;
49
50   tvec_parseargs(argc, argv, &tvstate, &argpos, &tvec_adhocconfig);
51   if (argpos < argc) die(2, "no input files expected");
52
53   TVEC_TESTGROUP(&tvstate, "fib-test") {
54     for (i = 0, a = 0, b = 1; i < FIBLIMIT; i++, t = b, b = a, a += t)
55       TVEC_TEST(&tvstate) {
56         if (i < RECFIBLIMIT) TVEC_CLAIMEQ_UINT(&tvstate, a, recfib(i));
57         TVEC_CLAIMEQ_UINT(&tvstate, a, iterfib(i));
58         TVEC_CLAIMEQ_UINT(&tvstate, a, expfib(i));
59       }
60   }
61
62   TVEC_TESTGROUP(&tvstate, "fib-bench") {
63     TVEC_BENCHMARK_DECLS;
64
65     if (tvec_benchprep(&tvstate, &tvec_benchstate, 0)) break;
66
67     dstr_reset(&d); dstr_putf(&d, "recfib, n = %u", RECFIBLIMIT);
68     TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1)
69       while (_bench_n--) ADMIRE(recfib(RECFIBLIMIT));
70
71     dstr_reset(&d); dstr_putf(&d, "iterfib, n = %u", FIBLIMIT);
72     TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1)
73       while (_bench_n--) ADMIRE(iterfib(FIBLIMIT));
74
75     dstr_reset(&d); dstr_putf(&d, "expfib, n = %u", FIBLIMIT);
76     TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1)
77       while (_bench_n--) ADMIRE(expfib(FIBLIMIT));
78   }
79
80   dstr_destroy(&d);
81   return (tvec_end(&tvstate));
82 }
83
84 /*----- That's all, folks -------------------------------------------------*/