112template < clock
id_t clock_type >
154template < clock
id_t clock_type >
158 if ( not is_running_ )
160 prev_elapsed_ += end_ - beg_;
161 end_ = beg_ = get_current_time();
166template < clock
id_t clock_type >
172 end_ = get_current_time();
177template < clock
id_t clock_type >
185 time_elapsed = get_current_time() - beg_ + prev_elapsed_;
190 time_elapsed = end_ - beg_ + prev_elapsed_;
192 return static_cast< double >( time_elapsed ) /
static_cast< double >( timeunit );
195template < clock
id_t clock_type >
205template < clock
id_t clock_type >
209 os << msg << elapsed( timeunit );
233 throw BadParameter(
"Invalid timeunit provided to stopwatch." );
238template < clock
id_t clock_type >
243 clock_gettime( clock_type, &now );
247template < clock
id_t clock_type >
283 return std::numeric_limits< double >().quiet_NaN();
288 return std::numeric_limits< double >().quiet_NaN();
300template < StopwatchGranularity detailed_timer, StopwatchParallelism threaded_timer >
307 template < clock
id_t ClockType >
309 std::vector< timers::StopwatchTimer< ClockType > >,
312 template < clock
id_t ClockType >
324 void print(
const std::string& msg =
"",
326 std::ostream& os = std::cout )
const;
328 void get_status(
Dictionary& d,
const std::string& walltime_name,
const std::string& cputime_name )
const;
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Exception to be thrown if a parameter cannot be set.
Definition exceptions.h:717
This template has two template arguments.
Definition stopwatch.h:302
std::conditional_t< enable_timer, InternalTimerType< ClockType >, NoOpStopwatch > StopwatchTimerType
Definition stopwatch.h:313
void reset()
Definition stopwatch_impl.h:190
double elapsed(timers::timeunit_t timeunit=timers::timeunit_t::SECONDS) const
Definition stopwatch_impl.h:110
StopwatchTimerType< CLOCK_THREAD_CPUTIME_ID > cputime_timer_
Definition stopwatch.h:336
static constexpr bool enable_timer
Definition stopwatch.h:303
StopwatchTimerType< CLOCK_MONOTONIC > walltime_timer_
Definition stopwatch.h:335
void stop()
Definition stopwatch_impl.h:63
void print(const std::string &msg="", timers::timeunit_t timeunit=timers::timeunit_t::SECONDS, std::ostream &os=std::cout) const
Definition stopwatch_impl.h:134
void get_status(Dictionary &d, const std::string &walltime_name, const std::string &cputime_name) const
Definition stopwatch_impl.h:157
static constexpr bool use_timer_array
Definition stopwatch.h:304
bool is_running_() const
Definition stopwatch_impl.h:86
std::conditional_t< use_timer_array, std::vector< timers::StopwatchTimer< ClockType > >, timers::StopwatchTimer< ClockType > > InternalTimerType
Definition stopwatch.h:310
void start()
Definition stopwatch_impl.h:36
This class represents a single timer which measures the execution time of a single thread for a given...
Definition stopwatch.h:114
void print(const std::string &msg="", timeunit_t timeunit=timeunit_t::SECONDS, std::ostream &os=std::cout) const
This method prints out the currently elapsed time.
Definition stopwatch.h:207
void start()
Starts or resumes the stopwatch, if it is not running already.
Definition stopwatch.h:156
bool is_running_
true between start() and stop()
Definition stopwatch.h:148
size_t beg_
clock (in ns) at which timer was last started
Definition stopwatch.h:145
void reset()
Resets the stopwatch.
Definition stopwatch.h:197
size_t prev_elapsed_
accumulated time of all start-stop intervals since last reset
Definition stopwatch.h:147
double elapsed(timeunit_t timeunit=timeunit_t::SECONDS) const
Returns the time elapsed between the start and stop of the stopwatch in the given unit.
Definition stopwatch.h:179
void stop()
Stops the stopwatch, if it is not stopped already.
Definition stopwatch.h:168
StopwatchTimer()
Creates a stopwatch that is not running.
Definition stopwatch.h:117
static size_t get_current_time()
Returns current time of clock_type in nanoseconds.
Definition stopwatch.h:240
size_t end_
clock (in ns) at which timer was last stopped (invariant: end_ >= beg_)
Definition stopwatch.h:146
timeunit_t
Definition stopwatch.h:99
std::ostream & operator<<(std::ostream &os, const StopwatchTimer< clock_type > &stopwatch)
Definition stopwatch.h:249
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
constexpr bool use_threaded_timers
Definition stopwatch.h:52
constexpr bool use_detailed_timers
Definition stopwatch.h:46
StopwatchParallelism
Definition stopwatch.h:62
@ MasterOnly
Only the master thread owns a stopwatch.
@ Threaded
Every thread measures an individual stopwatch.
StopwatchGranularity
Definition stopwatch.h:56
@ Detailed
Only measure if detailed stopwatches are activated.
@ Normal
Always measure stopwatch.
Definition stopwatch.h:258
void print(const std::string &, timers::timeunit_t, std::ostream &) const
Definition stopwatch.h:277
constexpr double elapsed(timers::timeunit_t) const noexcept
Definition stopwatch.h:286
constexpr void start() noexcept
Definition stopwatch.h:260
constexpr bool is_running_() const noexcept
Definition stopwatch.h:272
constexpr void stop() noexcept
Definition stopwatch.h:264
constexpr double elapsed() const noexcept
Definition stopwatch.h:281
constexpr void reset() noexcept
Definition stopwatch.h:268