Skip to content

ENH: New `Utilities::ScopedTimer` class, for lightweight profiling

A new class, ScopedTimer, which allows code blocks to be timed in a lightweight manner. To use, you just need to create a ScopedTimer instance at the beginning of the code block to be timed, e.g.:

void some_func(bool some_cond) {
  if (some_cond) {
    ScopedTimer t("some_func - true branch");
    // do work
  }
  else {
    ScopedTimer t("some_func - false branch");
    // do work
  }
}

When the ScopedTimer instance goes out of scope, its destructor will calculate the elapsed time, and emit a message to standard out, e.g. if some_func(false) is called:

some_func - false branch: 2.5 seconds
Edited by Paul McCarthy

Merge request reports

Loading