#ifndef __HIGHFREQCOUNTER_HPP__ #define __HIGHFREQCOUNTER_HPP__ /* ================================================================================ highFreqCounter.hpp v. 0.5.1.a © sam0delk1n, 2015 ================================================================================ */ #include #include namespace boolean { /* ================================================================================ highFreqCounter ================================================================================ */ class highFreqCounter final { public: const clockid_t clockid; auto begin( void ) noexcept ->void; auto end( void ) noexcept ->void; auto nsecGetTime( void ) const noexcept ->int64_t; auto operator=( const highFreqCounter& ) ->highFreqCounter& = delete; explicit highFreqCounter( const clockid_t clockid ); highFreqCounter( const highFreqCounter& ) = delete; ~highFreqCounter( void ) = default; private: int64_t nsecStartTime { 0 }; int64_t nsecLastDeltaTime { 0 }; }; /* ================================================================================ highFreqCounter::begin ================================================================================ */ inline auto highFreqCounter::begin( void ) noexcept ->void { timespec tspecStartTime; clock_gettime( clockid, &tspecStartTime ); nsecStartTime = static_cast< int64_t >( tspecStartTime.tv_sec ) * 1000000000 + tspecStartTime.tv_nsec; } /* ================================================================================ highFreqCounter::end ================================================================================ */ inline auto highFreqCounter::end( void ) noexcept ->void { timespec tspecEndTime; clock_gettime( clockid, &tspecEndTime ); const int64_t nsecEndTime { static_cast< int64_t >( tspecEndTime.tv_sec ) * 1000000000 + tspecEndTime.tv_nsec }; nsecLastDeltaTime = nsecEndTime - nsecStartTime; } /* ================================================================================ highFreqCounter::nsecGetTime ================================================================================ */ inline auto highFreqCounter::nsecGetTime( void ) const noexcept ->int64_t { return nsecLastDeltaTime; } /* ================================================================================ highFreqCounter::highFreqCounter ================================================================================ */ inline highFreqCounter::highFreqCounter( const clockid_t clockid ) : clockid( clockid ) {} }/*namespace boolean*/ #endif/*__HIGHFREQCOUNTER_HPP__*/