25 #ifndef TEST_MEASURE_H_INCLUDED
26 #define TEST_MEASURE_H_INCLUDED
28 #include <freerdp/config.h>
31 #include <winpr/string.h>
32 #include <winpr/sysinfo.h>
35 #include <sys/param.h>
38 #include <winpr/crt.h>
42 #define PROFILER_START(_prefix_)
45 #define MEASURE_LOOP_START(_prefix_, _count_)
46 #define MEASURE_LOOP_STOP
47 #define MEASURE_GET_RESULTS(_result_)
48 #define MEASURE_SHOW_RESULTS(_result_)
49 #define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_)
50 #define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_)
54 #ifdef GOOGLE_PROFILER
55 #include <gperftools/profiler.h>
56 #define PROFILER_START(_prefix_) \
59 char _path[PATH_MAX]; \
60 sprintf_s(_path, sizeof(_path), "./%s.prof", (_prefix_)); \
61 ProfilerStart(_path); \
63 #define PROFILER_STOP \
69 #define PROFILER_START(_prefix_)
73 extern float measure_delta_time(UINT64 t0, UINT64 t1);
74 extern void measure_floatprint(
float t,
char* output,
size_t len);
76 #define MEASURE_LOOP_START(_prefix_, _count_) \
78 int _count = (_count_); \
80 char str1[32] = { 0 }; \
81 char str2[32] = { 0 }; \
82 char* _prefix = _strdup(_prefix_); \
83 const UINT64 start = winpr_GetTickCount64NS(); \
84 PROFILER_START(_prefix); \
89 #define MEASURE_LOOP_STOP \
94 #define MEASURE_GET_RESULTS(_result_) \
96 const UINT64 stop = winpr_GetTickCount64NS(); \
97 const float delta = measure_delta_time(start, stop); \
98 (_result_) = (float)_count / delta; \
102 #define MEASURE_SHOW_RESULTS(_result_) \
104 const UINT64 stop = winpr_GetTickCount64NS(); \
105 const float delta = measure_delta_time(start, stop); \
106 (_result_) = (float)_count / delta; \
107 measure_floatprint((float)_count / delta, str1); \
108 printf("%s: %9d iterations in %5.1f seconds = %s/s \n", _prefix, _count, delta, str1); \
112 #define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_) \
114 const UINT64 stop = winpr_GetTickCount64NS(); \
115 const float delta = measure_delta_time(start, stop); \
116 measure_floatprint((float)_count / delta, str1); \
117 measure_floatprint((float)_count / delta * (_scale_), str2); \
118 printf("%s: %9d iterations in %5.1f seconds = %s/s = %s%s \n", _prefix, _count, delta, str1, \
123 #define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_) \
126 MEASURE_LOOP_START(_label_, _init_iter_); \
129 MEASURE_GET_RESULTS(_r); \
130 MEASURE_LOOP_START(_label_, _r* _test_time_); \
133 MEASURE_SHOW_RESULTS(_result_); \