XBinder  Version 2.6.x
rtxBench.h
Go to the documentation of this file.
1 /* Benchmark utility functions */
2 
6 #ifndef _RTXBENCH_H_
7 #define _RTXBENCH_H_
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #ifndef _WIN32_WCE
12 #define __need_timespec
13 #include <time.h>
14 #ifndef _NUCLEUS
15 #include <sys/stat.h>
16 #endif
17 #else
18 #include "rtxsrc/wceAddon.h"
19 #endif
20 #include "rtxsrc/rtxDiag.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define ITERCNT 10000L
27 
28 typedef struct {
29  clock_t timediff;
30  double avgMSec;
31 } OSRTBenchmarkTimes;
32 
33 typedef struct {
34  const char* program;
35  const char* encRules;
36  size_t itercnt;
37  size_t msgSize;
38  unsigned long encodeMsecs;
39  unsigned long decodeMsecs;
40 } OSRTBenchmarkData;
41 /*
42 #define __need_timespec
43 #include <time.h>
44 */
45 #define DECLARE_BENCHMARK \
46  struct timespec tp0, tp1, tp2, tp3; \
47  long __clk__ = 0; \
48  double __maxms__ = 0, __minms__ = 10000000000000.f;
49 
50 #define CLOCK_START \
51  clock_gettime(CLOCK_REALTIME, &tp0);
52 
53 #define CLOCK_STOP \
54  clock_gettime(CLOCK_REALTIME, &tp1);
55 
56 #define BEGIN_LOOP \
57  CLOCK_START \
58  for (__clk__ = 0; __clk__ < ITERCNT; __clk__ ++) { \
59  clock_gettime(CLOCK_REALTIME, &tp2);
60 
61 #define END_LOOP \
62  clock_gettime(CLOCK_REALTIME, &tp3); \
63  long _dst = tp3.tv_sec - tp2.tv_sec, \
64  _dnt = tp3.tv_nsec - tp2.tv_nsec; \
65  double _dmst = (_dst * 1000.f) + (_dnt / 1e6); \
66  \
67  if (_dmst < __minms__) __minms__ = _dmst; \
68  if (_dmst > __maxms__) __maxms__ = _dmst; \
69  } \
70  CLOCK_STOP
71 
72 #define PRINT_RESULTS_MS \
73  long _ds = tp1.tv_sec - tp0.tv_sec, \
74  _dn = tp1.tv_nsec - tp0.tv_nsec; \
75  double _dms = (_ds * 1000.f) + (_dn / 1e6); \
76  printf ("\t%.6f\t%.6f\t%.6f\t%.6f\n", _dms, __minms__, __maxms__, \
77  _dms/(float)ITERCNT);
78 
89 double rtxBenchAverageMS (clock_t start, clock_t finish, double icnt);
90 
91 void rtxBenchPrintResults
92 (const char* filename, const OSRTBenchmarkData* pdata);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 #endif
Common runtime functions for diagnostic tracing and debugging.
double rtxBenchAverageMS(clock_t start, clock_t finish, double icnt)
This function calculates the average number of milliseconds a test takes given the starting time...