Skip to content

Commit

Permalink
Don't use chrono in snitch headers
Browse files Browse the repository at this point in the history
As suggested in code review, don't include chrono in the snitch headers
since this increases compile times. Use a basic integral representation
type and then convert back and forth to chrono types in the source files
when actually reading clocks or calculating times.
  • Loading branch information
CrustyAuklet committed Jul 2, 2024
1 parent 2bfe6a7 commit 5f5afc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
7 changes: 3 additions & 4 deletions include/snitch/snitch_section.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#include "snitch/snitch_config.hpp"
#include "snitch/snitch_test_data.hpp"
#if SNITCH_WITH_TIMINGS
# include <chrono>
#endif

#include <type_traits>

namespace snitch::impl {
struct section_entry_checker {
Expand All @@ -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<std::size_t> start_time = 0;
#endif

SNITCH_EXPORT ~section_entry_checker();
Expand Down
23 changes: 17 additions & 6 deletions src/snitch_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
#if SNITCH_WITH_EXCEPTIONS
# include <exception>
#endif
#if SNITCH_WITH_TIMINGS
# include <chrono>
#endif

namespace snitch::impl {
#if SNITCH_WITH_TIMINGS
using fsec = std::chrono::duration<float>;
using snitch_clock = std::chrono::steady_clock;
#endif

section_entry_checker::~section_entry_checker() {
if (entered) {
#if SNITCH_WITH_EXCEPTIONS
Expand Down Expand Up @@ -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<float>(end_time - start_time).count();
const auto end_time = snitch_clock::now().time_since_epoch();
const auto duration =
std::chrono::duration_cast<fsec>(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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5f5afc6

Please sign in to comment.