diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-02-22 20:48:40 +1100 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-02-22 20:48:40 +1100 |
| commit | 1a05b6e111fa143ecd67491e548e5fc1db74f30e (patch) | |
| tree | dea26d53e11043691c31b7290d4ef5e7344a5a99 /bench/bench.h | |
| parent | 14b9f07efd4fba308fc24ff1d70fc7e274fc61ee (diff) | |
feat(bench): Add benchmarking
Diffstat (limited to 'bench/bench.h')
| -rw-r--r-- | bench/bench.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/bench/bench.h b/bench/bench.h index 1a7ef78..ac414ce 100644 --- a/bench/bench.h +++ b/bench/bench.h @@ -1,6 +1,55 @@ #ifndef TINYFF_BENCH_H_ #define TINYFF_BENCH_H_ +#include <time.h> +#define FF_BENCH_MAX_MARKERS 32 + +typedef struct { + const char *label; + clock_t tick; +} ff_bench_marker; + +typedef struct { + const char *label; + clock_t _start; + clock_t _end; + + ff_bench_marker markers[FF_BENCH_MAX_MARKERS]; + int _mcount; +} ff_bench; + +// These need to be inline so they are fast + +static inline ff_bench ff_bench_start(const char* label) { + ff_bench b; + b.label = label; + b._start = clock(); + b._end = 0; + + // Markers + b._mcount = 0; + + return b; +} + +static inline void ff_bench_end(ff_bench *b) { + b->_end = clock(); +} + +static inline void ff_bench_mark(ff_bench *b, const char *label) { + if (b->_mcount >= FF_BENCH_MAX_MARKERS) return; + + ff_bench_marker m; + m.label = label; + m.tick = clock(); + + b->markers[b->_mcount] = m; + b->_mcount++; +} + +static inline double ff_bench_seconds(const ff_bench *b) { + return (double)(b->_end - b->_start) / CLOCKS_PER_SEC; +} #endif // TINYFF_BENCH_H
\ No newline at end of file |
