spla
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1/**********************************************************************************/
2/* This file is part of spla project */
3/* https://github.com/SparseLinearAlgebra/spla */
4/**********************************************************************************/
5/* MIT License */
6/* */
7/* Copyright (c) 2023 SparseLinearAlgebra */
8/* */
9/* Permission is hereby granted, free of charge, to any person obtaining a copy */
10/* of this software and associated documentation files (the "Software"), to deal */
11/* in the Software without restriction, including without limitation the rights */
12/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
13/* copies of the Software, and to permit persons to whom the Software is */
14/* furnished to do so, subject to the following conditions: */
15/* */
16/* The above copyright notice and this permission notice shall be included in all */
17/* copies or substantial portions of the Software. */
18/* */
19/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
20/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
21/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
22/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
23/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
24/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
25/* SOFTWARE. */
26/**********************************************************************************/
27
28#ifndef SPLA_TIMER_HPP
29#define SPLA_TIMER_HPP
30
31#include "config.hpp"
32
33#include <chrono>
34#include <iostream>
35#include <ostream>
36#include <vector>
37
38namespace spla {
39
49 class Timer {
50 public:
53
54 SPLA_API void start();
55 SPLA_API void stop();
56 SPLA_API void lap_begin();
57 SPLA_API void lap_end();
58 SPLA_API void print(std::ostream& out = std::cout) const;
59 [[nodiscard]] SPLA_API double get_elapsed_ms() const;
60 [[nodiscard]] SPLA_API double get_elapsed_sec() const;
61 [[nodiscard]] SPLA_API const std::vector<double>& get_laps_ms() const;
62
63 private:
64 using clock = std::chrono::steady_clock;
65 using us = std::chrono::microseconds;
66 using point = clock::time_point;
67
68 std::vector<double> m_laps;
69 point m_start;
70 point m_prev;
71 point m_end;
72 };
73
78}// namespace spla
79
80#endif//SPLA_TIMER_HPP
Simple timer to measure intervals of time on CPU-side.
Definition timer.hpp:49
void start()
Definition timer.cpp:32
double get_elapsed_ms() const
Definition timer.cpp:52
void print(std::ostream &out=std::cout) const
Definition timer.cpp:48
double get_elapsed_sec() const
Definition timer.cpp:55
void lap_end()
Definition timer.cpp:42
const std::vector< double > & get_laps_ms() const
Definition timer.cpp:59
void lap_begin()
Definition timer.cpp:39
void stop()
Definition timer.cpp:36
#define SPLA_API
Definition config.hpp:43
Definition algorithm.hpp:37