@@@ misc mess
[mLib] / test / bench.h
index 0645068..2484584 100644 (file)
@@ -34,6 +34,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <time.h>
+
 #ifndef MLIB_BITS_H
 #  include "bits.h"
 #endif
@@ -49,7 +51,11 @@ struct bench_time {
 #define BTF_TIMEOK 1u                  /*   @s@ ad @ns@ slots are value */
 #define BTF_CYOK 2u                    /*   @cy@ slot is valid */
 #define BTF_ANY (BTF_TIMEOK | BTF_CYOK)        /*   some part is useful */
-  kludge64 s; uint32 ns;               /* real time, seconds and nanos */
+  union {
+    struct { kludge64 s; uint32 ns; } ts; /* @struct timespec@-ish */
+    clock_t clk;                       /* @clock@ */
+    kludge64 rawns;                    /* raw nanosecond count */
+  } t;                                 /* time */
   kludge64 cy;                         /* count of CPU cycles */
 };
 
@@ -64,8 +70,21 @@ struct bench_timerops {
   void (*describe)(struct bench_timer */*bt*/, dstr */*d*/);
     /* Write a description of the timer to @d@. */
 
-  void (*now)(struct bench_timer */*bt*/, struct bench_time */*t_out*/);
-    /* Fill in @*t_out@ with the current time. v*/
+  int (*now)(struct bench_timer */*bt*/, struct bench_time */*t_out*/,
+             unsigned /*f*/);
+#define BTF_T0 0u                      /* fetching first time of a pair */
+#define BTF_T1 1u                      /* fetching second time of a pair */
+    /* Fill in @*t_out@ with the current time.  Return zero on success
+     * %%\emph{or} permanent failure; return %$-1$% on temporary failure.
+     */
+
+  void (*diff)(struct bench_timer */*bt*/,
+              struct bench_timing */*delta_out*/,
+              const struct bench_time */*t0*/,
+              const struct bench_time */*t1*/);
+    /* Subtract the time @t0@ from the time @t1@, leaving the result in
+     * @*delta_out@, setting flags as appropriate.
+     */
 
   void (*destroy)(struct bench_timer */*bt*/);
     /* Release the timer and any resources it holds. */