NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
timer.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2020 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef TIMER_HPP
20#define TIMER_HPP
21
22#include <chrono>
23#include <string>
24#include "../../kernel.hpp"
25#include "tools.hpp"
26
27class Timer
28{
29 private:
30 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> m_StartPoint;
31 std::string m_ScopeName;
32
33 public:
34 Timer(const std::string& scopeName)
35 {
36 m_ScopeName = scopeName;
37 m_StartPoint = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
38 }
39
41 {
42 Stop();
43 }
44
45 void Stop()
46 {
47 auto endTimePoint = std::chrono::time_point_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now());
48 std::chrono::nanoseconds time_span = endTimePoint - m_StartPoint;
49
50 NumeReKernel::print("[" + m_ScopeName + "] Measured run time: " + toString(time_span.count() / 1000.0, 14) + " mus.");
51 }
52};
53
54
55#endif // TIMER_HPP
56
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
Definition: kernel.cpp:2636
Definition: timer.hpp:28
~Timer()
Definition: timer.hpp:40
std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > m_StartPoint
Definition: timer.hpp:30
Timer(const std::string &scopeName)
Definition: timer.hpp:34
std::string m_ScopeName
Definition: timer.hpp:31
void Stop()
Definition: timer.hpp:45
std::string toString(int)
Converts an integer to a string without the Settings bloat.