Mantid
Loading...
Searching...
No Matches
Timer.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidKernel/DllConfig.h"
13#include <chrono>
14#include <iosfwd>
15#include <string>
16
17namespace Mantid {
18namespace Kernel {
19
20using time_point_ns = std::chrono::time_point<std::chrono::high_resolution_clock>;
21
27class MANTID_KERNEL_DLL Timer {
28public:
29 Timer();
30 virtual ~Timer() = default;
31
32 float elapsed(bool reset = true);
33 float elapsed_no_reset() const;
34 std::string str() const;
35 void reset();
36
37private:
39};
40
41MANTID_KERNEL_DLL std::ostream &operator<<(std::ostream &, const Timer &);
42
43class MANTID_KERNEL_DLL CodeBlockTimer {
44public:
45 CodeBlockTimer() = delete;
46 CodeBlockTimer(const std::string &name, std::ostream &output);
48
49private:
50 std::string m_name;
51 std::ostream &m_out;
52 std::chrono::time_point<std::chrono::system_clock> m_start;
53};
54
55class MANTID_KERNEL_DLL CodeBlockMultipleTimer {
56public:
57 class MANTID_KERNEL_DLL TimeAccumulator {
58 public:
59 TimeAccumulator() = delete;
60 TimeAccumulator(const std::string &name);
61
62 public:
63 void reset();
64 void increment(const double time_sec);
65 double getElapsed() const;
66 size_t getNumberOfEntrances() const;
67 std::string toString() const;
68
69 private:
70 std::string m_name;
71 double m_elapsed_sec{0.0};
72 size_t m_number_of_entrances{0};
73 };
74
75public:
79
80private:
82 std::chrono::time_point<std::chrono::system_clock> m_start;
83};
84
85MANTID_KERNEL_DLL std::ostream &operator<<(std::ostream &, const CodeBlockMultipleTimer::TimeAccumulator &);
86} // namespace Kernel
87} // namespace Mantid
std::string name
Definition Run.cpp:60
TimeAccumulator & m_accumulator
Definition Timer.h:81
std::chrono::time_point< std::chrono::system_clock > m_start
Definition Timer.h:82
std::chrono::time_point< std::chrono::system_clock > m_start
Definition Timer.h:52
A simple class that provides a wall-clock (not processor time) timer.
Definition Timer.h:27
virtual ~Timer()=default
time_point_ns m_start
The starting time.
Definition Timer.h:38
std::chrono::time_point< std::chrono::high_resolution_clock > time_point_ns
Definition Algorithm.h:39
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition CPUTimer.cpp:86
std::string toString(const T &value)
Convert values to strings.
Helper class which provides the Collimation Length for SANS instruments.