00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 * END_LOOP
00035 *
00036 * PRINT_RESULTS_MS
00037 *
00038 * Convenience macros to start and stop the performance clock are also
00039 * provided in case a loop is not necessary. In this case, the ITERCNT
00040 * value should be redefined to the number of cases being tested.
00041 *
00042 * These timers should be reasonable accurate within microsecond resolution,
00043 * but results will vary from platform to platform. On GNU/Linux systems,
00044 * it is necessary to link against librt.a.
00045 *
00046 * If a program is terminated unexpectedly, results may fail to print since
00047 * the output buffer may not be flushed. If exception handling is used,
00048 * make sure to call fflush(stdout) or the appropriate call for your
00049 * platform. */
00050
00051 #ifndef __RTXCLOCK_H__
00052 #define __RTXCLOCK_H__
00053
00054 #include <cstdio>
00055
00056 #define ITERCNT 100000L
00057
00058 #ifndef MSC_VER
00059
00060 #include <time.h>
00061
00062 #define DECLARE_BENCHMARK \
00063 timespec tp0, tp1; \
00064 long __clk__ = 0;
00065
00066 #define CLOCK_START \
00067 clock_gettime(CLOCK_REALTIME, &tp0);
00068
00069 #define CLOCK_STOP \
00070 clock_gettime(CLOCK_REALTIME, &tp1);
00071
00072 #define BEGIN_LOOP \
00073 CLOCK_START \
00074 for (__clk__ = 0; __clk__ < ITERCNT; __clk__ ++) {
00075
00076 #define END_LOOP \
00077 } \
00078 CLOCK_STOP
00079
00080 #define PRINT_RESULTS_MS \
00081 long _ds = tp1.tv_sec - tp0.tv_sec, \
00082 _dn = tp1.tv_nsec - tp0.tv_nsec; \
00083 double _dms = (_ds * 1000.f) + (_dn / 1e6); \
00084 printf ("\t%.6f\t%.6f\n", _dms, _dms/(float)ITERCNT);
00085
00086 #else
00087
00088 #include <windows.h>
00089
00090 #define DECLARE_BENCHMARK \
00091 LARGE_INTEGER _start, _stop, _freq; \
00092 long __clk__ = 0; \
00093 QueryPerformanceFrequency(&_freq);
00094
00095 #define CLOCK_START \
00096 QueryPerformanceCounter(&_start);
00097
00098 #define CLOCK_STOP \
00099 QueryPerformanceCounter(&_stop);
00100
00101 #define BEGIN_LOOP \
00102 CLOCK_START \
00103 for (__clk__ = 0; __clk__ < ITERCNT; __clk__ ++) {
00104
00105 #define END_LOOP \
00106 } \
00107 CLOCK_END
00108
00109 #define PRINT_RESULTS_MS \
00110 double _delta = (_stop.QuadPart - _start.QuadPart), \
00111 _total = _delta / (double)_freq.QuadPart * 1000; \
00112 printf("\t%.6f\t%.6f\n", _total, _total/(float)ITERCNT);
00113
00114 #endif
00115
00116 #endif
00117