Commit | Line | Data |
---|---|---|
b1a20bee MW |
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 | ||
b1a20bee MW |
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 | ||
289651a7 | 39 | #include "example.h" |
b1a20bee | 40 | |
289651a7 | 41 | /*----- Main code ---------------------------------------------------------*/ |
b1a20bee MW |
42 | |
43 | int main(int argc, char *argv[]) | |
44 | { | |
45 | struct tvec_state tvstate; | |
46 | int argpos; | |
47 | unsigned long i, a, b, t; | |
289651a7 | 48 | dstr d = DSTR_INIT; |
b1a20bee MW |
49 | |
50 | tvec_parseargs(argc, argv, &tvstate, &argpos, &tvec_adhocconfig); | |
51 | if (argpos < argc) die(2, "no input files expected"); | |
52 | tvec_adhoc(&tvstate); | |
53 | ||
b1a20bee MW |
54 | TVEC_TESTGROUP(&tvstate, "fib-test") { |
55 | for (i = 0, a = 0, b = 1; i < FIBLIMIT; i++, t = b, b = a, a += t) | |
56 | TVEC_TEST(&tvstate) { | |
57 | if (i < 40) TVEC_CLAIMEQ_UINT(&tvstate, a, recfib(i)); | |
58 | TVEC_CLAIMEQ_UINT(&tvstate, a, iterfib(i)); | |
59 | TVEC_CLAIMEQ_UINT(&tvstate, a, expfib(i)); | |
60 | } | |
61 | } | |
62 | ||
63 | TVEC_TESTGROUP(&tvstate, "fib-bench") { | |
64 | TVEC_BENCHMARK_DECLS; | |
65 | ||
66 | if (tvec_benchprep(&tvstate, &tvec_benchstate, 0)) break; | |
67 | ||
289651a7 MW |
68 | dstr_reset(&d); dstr_putf(&d, "recfib, n = %u", RECFIBLIMIT); |
69 | TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1) | |
70 | while (_bench_n--) ADMIRE(recfib(RECFIBLIMIT)); | |
71 | ||
72 | dstr_reset(&d); dstr_putf(&d, "iterfib, n = %u", FIBLIMIT); | |
73 | TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1) | |
b1a20bee | 74 | while (_bench_n--) ADMIRE(iterfib(FIBLIMIT)); |
289651a7 MW |
75 | |
76 | dstr_reset(&d); dstr_putf(&d, "expfib, n = %u", FIBLIMIT); | |
77 | TVEC_BENCHMARK(d.buf, &tvstate, tvec_benchstate, BTU_OP, 1) | |
b1a20bee MW |
78 | while (_bench_n--) ADMIRE(expfib(FIBLIMIT)); |
79 | } | |
80 | ||
289651a7 | 81 | dstr_destroy(&d); |
b1a20bee MW |
82 | return (tvec_end(&tvstate)); |
83 | } | |
84 | ||
85 | /*----- That's all, folks -------------------------------------------------*/ |