43 #include "utils/inttypes.h" 49 #define DEBUG_FLAG(x) bool dbg_flag = x; 55 std::cerr << x << std::endl; \ 63 std::cerr << #x << ":" << x << std::endl; \ 68 #define DEBUGWHERE(x) \ 71 std::cerr << __FILE__ << ":" << __LINE__ << ": " \ 72 << #x << ":" << x << std::endl; \ 76 #if defined(PROFILE) // Profiler works 78 #define PROFILELOG(x) \ 81 std::cout << x << std::endl; \ 86 #define PROFILELOGEXP(x) \ 89 std::cout << #x << ":" << x << std::endl; \ 94 #define PROFILELOGWHERE(x) \ 97 std::cout << #x << ":" << x << " at " << __FILE__ << " line " \ 98 << __LINE__ << std::endl; \ 102 #else // #if!defined(PROFILE) // profiling a noop 103 #define PROFILELOG(x) 104 #define PROFILELOGEXP(x) 105 #define PROFILELOGWHERE(x) 109 #define TIC(t) t = timeNow() 110 #define TOC(t) duration(timeNow() - t) 111 #define TOC_NS(t) duration_ns(timeNow() - t) 112 #define TOC_US(t) duration_us(timeNow() - t) 113 #define TOC_MS(t) duration_ms(timeNow() - t) 120 #if !defined(PROFILE) 124 #define DEBUG_FLAG(x) 127 #define DEBUGWHERE(x) 129 #define PROFILELOG(x) 130 #define PROFILELOGEXP(x) 131 #define PROFILELOGWHERE(x) 133 #define TIC(t) t = timeNow() 134 #define TOC(t) std::chrono::steady_clock::duration::zero().count() 135 #define TOC_NS(t) std::chrono::steady_clock::duration::zero().count() 136 #define TOC_US(t) std::chrono::steady_clock::duration::zero().count() 137 #define TOC_MS(t) std::chrono::steady_clock::duration::zero().count() 142 #define DEBUG_FLAG(x) 145 #define DEBUGWHERE(x) 147 #define PROFILELOG(x) \ 150 std::cerr << x << std::endl; \ 155 #define PROFILELOGEXP(x) \ 158 std::cout << #x << ":" << x << std::endl; \ 163 #define PROFILELOGWHERE(x) \ 166 std::cout << #x << ":" << x << " at " << __FILE__ << " line " \ 167 << __LINE__ LL std::endl; \ 171 #define TIC(t) t = timeNow() 172 #define TOC(t) duration(timeNow() - t) 173 #define TOC_NS(t) duration_ns(timeNow() - t) 174 #define TOC_US(t) duration_us(timeNow() - t) 175 #define TOC_MS(t) duration_ms(timeNow() - t) 181 typedef std::chrono::high_resolution_clock::time_point TimeVar;
183 #define duration(a) \ 184 std::chrono::duration_cast<std::chrono::milliseconds>(a).count() 185 #define duration_ns(a) \ 186 std::chrono::duration_cast<std::chrono::nanoseconds>(a).count() 187 #define duration_us(a) \ 188 std::chrono::duration_cast<std::chrono::microseconds>(a).count() 189 #define duration_ms(a) \ 190 std::chrono::duration_cast<std::chrono::milliseconds>(a).count() 191 #define timeNow() std::chrono::high_resolution_clock::now() 193 double currentDateTime();
195 template <
typename F,
typename... Args>
196 double funcTime(F func, Args&&... args) {
197 TimeVar t1 = timeNow();
198 func(std::forward<Args>(args)...);
199 return duration(timeNow() - t1);