Raptor 3.0.0-rc.1
A fast and space-efficient pre-filter for querying very large collections of nucleotide sequences
 
timer.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <atomic>
16#include <cassert>
17#include <chrono>
18
19namespace raptor
20{
21
22enum class concurrent
23{
24 no,
25 yes
26};
27
28template <concurrent concurrency>
29class timer
30{
31private:
32 static constexpr bool is_concurrent{concurrency == concurrent::yes};
33
34 using rep_t =
36
37 template <concurrent concurrency_>
38 friend class timer;
39
40public:
41 timer() = default;
42 timer(timer &&) = default;
43 timer & operator=(timer &&) = default;
44 ~timer() = default;
45
46 timer(timer const & other)
47 requires (!is_concurrent)
48 = default;
49 timer & operator=(timer const & other)
50 requires (!is_concurrent)
51 = default;
52
53 timer(timer const & other)
54 requires is_concurrent
55 : start_{other.start_}, stop_{other.stop_}, ticks{other.ticks.load()}
56 {}
57 timer & operator=(timer const & other)
58 requires is_concurrent
59 {
60 start_ = other.start_;
61 stop_ = other.stop_;
62 ticks = other.ticks.load();
63 return *this;
64 }
65
66 void start()
67 {
69 }
70
71 void stop()
72 {
74 assert(stop_ >= start_);
75 ticks += (stop_ - start_).count();
76 }
77
78 template <concurrent concurrency_>
79 void operator+=(timer<concurrency_> const & other)
80 {
81 ticks += other.ticks;
82 }
83
84 double in_seconds() const
85 requires is_concurrent
86 {
87 return std::chrono::duration<double>(std::chrono::steady_clock::duration{ticks.load()}).count();
88 }
89
90 // GCOVR_EXCL_START
91 double in_seconds() const
92 requires (!is_concurrent)
93 {
94 return std::chrono::duration<double>(std::chrono::steady_clock::duration{ticks}).count();
95 }
96 // GCOVR_EXCL_STOP
97
98private:
99 std::chrono::steady_clock::time_point start_{std::chrono::time_point<std::chrono::steady_clock>::max()};
100 std::chrono::steady_clock::time_point stop_{};
101 rep_t ticks{};
102};
103
104} // namespace raptor
Definition: timer.hpp:30