Mantid
Loading...
Searching...
No Matches
Timer.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10#include "MantidKernel/Timer.h"
11#include <chrono>
12#include <ostream>
13#include <sstream>
14
15namespace Mantid::Kernel {
16
20Timer::Timer() : m_start(std::chrono::high_resolution_clock::now()) {}
21
28float Timer::elapsed(bool reset) {
29 float retval = elapsed_no_reset();
30 if (reset)
31 this->reset();
32 return retval;
33}
34
41 const auto now = std::chrono::high_resolution_clock::now();
42 std::chrono::duration<float> duration = now - m_start;
43
44 return duration.count();
45}
46
48void Timer::reset() { m_start = std::chrono::high_resolution_clock::now(); }
49
51std::string Timer::str() const {
52 std::stringstream buffer;
53 buffer << this->elapsed_no_reset() << "s";
54 return buffer.str();
55}
56
58std::ostream &operator<<(std::ostream &out, const Timer &obj) {
59 out << obj.str();
60 return out;
61}
62
63} // namespace Mantid::Kernel
double obj
the value of the quadratic function
A simple class that provides a wall-clock (not processor time) timer.
Definition: Timer.h:27
float elapsed_no_reset() const
Returns the wall-clock time elapsed in seconds since the Timer object's creation, or the last call to...
Definition: Timer.cpp:40
Timer()
Constructor.
Definition: Timer.cpp:20
float elapsed(bool reset=true)
Returns the wall-clock time elapsed in seconds since the Timer object's creation, or the last call to...
Definition: Timer.cpp:28
void reset()
Explicitly reset the timer.
Definition: Timer.cpp:48
time_point_ns m_start
The starting time.
Definition: Timer.h:38
std::string str() const
Convert the elapsed time (without reseting) to a string.
Definition: Timer.cpp:51
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86
STL namespace.