struct Prof_Scope_Print { Prof_Scope_Print(const char *name) : scope_name { name }, scope_start_t { std::chrono::high_resolution_clock::now() } {} ~Prof_Scope_Print() { using namespace std::chrono; time_point scope_end_t = high_resolution_clock::now(); duration scope_duration = duration_cast(scope_end_t - scope_start_t); fprintf(stderr, "[profile] %s took %.4f ms\n", scope_name, scope_duration.count() * 0.001f); } const char *scope_name; std::chrono::time_point scope_start_t; }; #define TIMED_SCOPE() const Prof_Scope_Print CONCAT_STR(_prof, __LINE__) { __func__ } #define TIMED_SCOPE_NAME(name) const Prof_Scope_Print CONCAT_STR(_prof, __LINE__) { name }