36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#define TIMING_START(_name) \
|
|
struct { \
|
|
struct entry { \
|
|
std::string name; \
|
|
std::chrono::system_clock::time_point ts; \
|
|
}; \
|
|
\
|
|
std::string name; \
|
|
std::chrono::system_clock::time_point begin; \
|
|
std::chrono::system_clock::time_point end; \
|
|
std::deque<entry> timings; \
|
|
} _name ##_timings; \
|
|
_name ##_timings.begin = std::chrono::system_clock::now(); \
|
|
|
|
#define TIMING_STEP(name, step) \
|
|
name ##_timings.timings.push_back({step, std::chrono::system_clock::now()});
|
|
|
|
#define TIMING_FINISH(_name) \
|
|
([&](){ \
|
|
_name ##_timings.end = std::chrono::system_clock::now(); \
|
|
std::string result; \
|
|
result = "timings for " + _name ##_timings.name + ": "; \
|
|
result += std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(_name ##_timings.end - _name ##_timings.begin).count()) + "ms"; \
|
|
\
|
|
auto tp = _name ##_timings.begin; \
|
|
for(const auto& entry : _name ##_timings.timings) { \
|
|
result += "\n "; \
|
|
result += "- " + entry.name + ": "; \
|
|
result += "@" + std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(entry.ts - _name ##_timings.begin).count()) + "ms"; \
|
|
result += ": " + std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(entry.ts - tp).count()) + "ms"; \
|
|
tp = entry.ts; \
|
|
} \
|
|
return result; \
|
|
})() |