diff --git a/include/snitch/snitch_section.hpp b/include/snitch/snitch_section.hpp index 2a0365a9..2d570797 100644 --- a/include/snitch/snitch_section.hpp +++ b/include/snitch/snitch_section.hpp @@ -3,9 +3,8 @@ #include "snitch/snitch_config.hpp" #include "snitch/snitch_test_data.hpp" -#if SNITCH_WITH_TIMINGS -# include -#endif + +#include namespace snitch::impl { struct section_entry_checker { @@ -16,7 +15,7 @@ struct section_entry_checker { std::size_t failures = 0; std::size_t allowed_failures = 0; #if SNITCH_WITH_TIMINGS - std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); + std::make_signed_t start_time = 0; #endif SNITCH_EXPORT ~section_entry_checker(); diff --git a/src/snitch_section.cpp b/src/snitch_section.cpp index 10b18526..2b718e7a 100644 --- a/src/snitch_section.cpp +++ b/src/snitch_section.cpp @@ -7,8 +7,16 @@ #if SNITCH_WITH_EXCEPTIONS # include #endif +#if SNITCH_WITH_TIMINGS +# include +#endif namespace snitch::impl { +#if SNITCH_WITH_TIMINGS +using fsec = std::chrono::duration; +using snitch_clock = std::chrono::steady_clock; +#endif + section_entry_checker::~section_entry_checker() { if (entered) { #if SNITCH_WITH_EXCEPTIONS @@ -39,12 +47,13 @@ section_entry_checker::~section_entry_checker() { // since then we will know if there is any sibling. state.sections.leaf_executed = true; #if SNITCH_WITH_TIMINGS - const auto end_time = std::chrono::steady_clock::now(); - const float duration = std::chrono::duration(end_time - start_time).count(); + const auto end_time = snitch_clock::now().time_since_epoch(); + const auto duration = + std::chrono::duration_cast(end_time - snitch_clock::duration{start_time}); state.reg.report_callback( - state.reg, - event::section_ended{ - data.id, data.location, false, asserts, failures, allowed_failures, duration}); + state.reg, event::section_ended{ + data.id, data.location, false, asserts, failures, allowed_failures, + duration.count()}); #else state.reg.report_callback( state.reg, @@ -91,7 +100,9 @@ section_entry_checker::operator bool() { state.sections.levels.push_back({}); } - +#if SNITCH_WITH_TIMINGS + start_time = snitch_clock::now().time_since_epoch().count(); +#endif ++state.sections.depth; asserts = state.asserts; failures = state.failures;