@@@ tvec wip
[mLib] / test / bench.h
1 /* -*-c-*-
2 *
3 * Benchmarking support
4 *
5 * (c) 2023 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 #ifndef MLIB_BENCH_H
29 #define MLIB_BENCH_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #ifndef MLIB_BITS_H
38 # include "bits.h"
39 #endif
40
41 /*----- Data structures ---------------------------------------------------*/
42
43 struct bench_time {
44 unsigned f;
45 #define BTF_TIMEOK 1u
46 #define BTF_CYOK 2u
47 #define BTF_ANY (BTF_TIMEOK | BTF_CYOK)
48 kludge64 s; uint32 ns;
49 kludge64 cy;
50 };
51
52 struct bench_timing {
53 unsigned f;
54 double n, t, cy;
55 };
56
57 struct bench_timer { const struct bench_timerops *ops; };
58
59 struct bench_timerops {
60 void (*now)(struct bench_timer */*bt*/, struct bench_time */*t_out*/);
61 void (*destroy)(struct bench_timer */*bt*/);
62 };
63
64 struct bench_state {
65 struct bench_timer *tm;
66 double target_s;
67 unsigned f;
68 struct { double m, c; } clk, cy;
69 };
70
71 typedef void bench_fn(unsigned long /*n*/, void */*p*/);
72
73 /*----- Functions provided ------------------------------------------------*/
74
75 extern struct bench_timer *bench_createtimer(void);
76
77 extern void bench_init(struct bench_state */*b*/,
78 struct bench_timer */*tm*/);
79
80 extern void bench_destroy(struct bench_state */*b*/);
81
82 extern int bench_calibrate(struct bench_state */*b*/);
83
84 extern int bench_measure(struct bench_timing */*t_out*/,
85 struct bench_state */*b*/,
86 double /*base*/, bench_fn */*fn*/, void */*p*/);
87
88 /*----- That's all, folks -------------------------------------------------*/
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif