Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/oneapi/tbb/tick_count.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (c) 2005-2021 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #ifndef __TBB_tick_count_H
0018 #define __TBB_tick_count_H
0019 
0020 #include <chrono>
0021 
0022 #include "detail/_namespace_injection.h"
0023 
0024 namespace tbb {
0025 namespace detail {
0026 namespace d1 {
0027 
0028 
0029 //! Absolute timestamp
0030 /** @ingroup timing */
0031 class tick_count {
0032 public:
0033     using clock_type = typename std::conditional<std::chrono::high_resolution_clock::is_steady,
0034         std::chrono::high_resolution_clock, std::chrono::steady_clock>::type;
0035 
0036     //! Relative time interval.
0037     class interval_t : public clock_type::duration {
0038     public:
0039         //! Construct a time interval representing zero time duration
0040         interval_t() : clock_type::duration(clock_type::duration::zero()) {}
0041 
0042         //! Construct a time interval representing sec seconds time duration
0043         explicit interval_t( double sec )
0044             : clock_type::duration(std::chrono::duration_cast<clock_type::duration>(std::chrono::duration<double>(sec))) {}
0045 
0046         //! Return the length of a time interval in seconds
0047         double seconds() const {
0048             return std::chrono::duration_cast<std::chrono::duration<double>>(*this).count();
0049         }
0050 
0051         //! Extract the intervals from the tick_counts and subtract them.
0052         friend interval_t operator-( const tick_count& t1, const tick_count& t0 );
0053 
0054         //! Add two intervals.
0055         friend interval_t operator+( const interval_t& i, const interval_t& j ) {
0056             return interval_t(std::chrono::operator+(i, j));
0057         }
0058 
0059         //! Subtract two intervals.
0060         friend interval_t operator-( const interval_t& i, const interval_t& j ) {
0061             return interval_t(std::chrono::operator-(i, j));
0062         }
0063 
0064     private:
0065         explicit interval_t( clock_type::duration value_ ) : clock_type::duration(value_) {}
0066     };
0067 
0068     tick_count() = default;
0069 
0070     //! Return current time.
0071     static tick_count now() {
0072         return clock_type::now();
0073     }
0074 
0075     //! Subtract two timestamps to get the time interval between
0076     friend interval_t operator-( const tick_count& t1, const tick_count& t0 ) {
0077         return tick_count::interval_t(t1.my_time_point - t0.my_time_point);
0078     }
0079 
0080     //! Return the resolution of the clock in seconds per tick.
0081     static double resolution() {
0082         return static_cast<double>(interval_t::period::num) / interval_t::period::den;
0083     }
0084 
0085 private:
0086     clock_type::time_point my_time_point;
0087     tick_count( clock_type::time_point tp ) : my_time_point(tp) {}
0088 };
0089 
0090 } // namespace d1
0091 } // namespace detail
0092 
0093 inline namespace v1 {
0094     using detail::d1::tick_count;
0095 } // namespace v1
0096 
0097 } // namespace tbb
0098 
0099 #endif /* __TBB_tick_count_H */