diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bc4b094..fc303083 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,6 @@ set(C4CORE_SRC_FILES c4/substr.hpp c4/substr_fwd.hpp c4/szconv.hpp - c4/time.hpp - c4/time.cpp c4/type_name.hpp c4/types.hpp c4/unrestrict.hpp diff --git a/src/c4/time.cpp b/src/c4/time.cpp deleted file mode 100644 index cbf56c44..00000000 --- a/src/c4/time.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "c4/time.hpp" - -#if defined(C4_WIN) -# include "c4/windows.hpp" -#elif defined(C4_LINUX) -# include -#else -# include -#endif - -#ifdef __clang__ -# pragma clang diagnostic push -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" -#endif - -namespace c4 { - -//----------------------------------------------------------------------------- -/** a general-use time stamp in microseconds (usecs). - * Although this is timed precisely, there may be some issues. - * Eg, concurrent or heavy use may cause penalties. - * @see http://stackoverflow.com/questions/2414359/microsecond-resolution-timestamps-on-windows - * @see https://www.strchr.com/performance_measurements_with_rdtsc - * @see https://msdn.microsoft.com/en-us/library/windows/desktop/ee417693(v=vs.85).aspx */ -time_type currtime() -{ -#ifdef C4_WIN - time_type ifreq; - LARGE_INTEGER freq; - QueryPerformanceFrequency(&freq); - ifreq = time_type(1.e6) / time_type(freq.QuadPart); - LARGE_INTEGER ts; - QueryPerformanceCounter(&ts); - time_type usecs = time_type(ts.QuadPart) * ifreq; - return usecs; -#elif defined(C4_LINUX) - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - time_type usecs = time_type(1.e6) * time_type(ts.tv_sec) - + time_type(1.e-3) * time_type(ts.tv_nsec); - return usecs; -#else - auto time_point = std::chrono::high_resolution_clock::now(); - auto duration = time_point.time_since_epoch(); - auto usecs_d = std::chrono::duration_cast(duration); - time_type usecs = (time_type)usecs_d.count(); - return usecs; -#endif -} - -#ifdef __clang__ -# pragma clang diagnostic pop -#elif defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - -} // namespace c4 diff --git a/src/c4/time.hpp b/src/c4/time.hpp deleted file mode 100644 index 773dbced..00000000 --- a/src/c4/time.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _C4_TIME_HPP_ -#define _C4_TIME_HPP_ - -#include "c4/config.hpp" - -#ifdef __clang__ -# pragma clang diagnostic push -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" -#endif - -/** @def C4_TIME_TYPE the type of the value to hold time */ - -namespace c4 { - -using time_type = C4_TIME_TYPE; - -time_type currtime(); // microsecs - -/** execution time, in microsecs */ -inline time_type exetime() -{ - static const time_type atstart = currtime(); - time_type now = currtime() - atstart; - return now; -} - -/** do a spin loop for at least the given time */ -inline void busy_wait(time_type microsecs) -{ - time_type end = currtime() + microsecs; - while(currtime() < end) - { - C4_KEEP_EMPTY_LOOP; - } -} - -//----------------------------------------------------------------------------- -/** converts automatically from/to microseconds. */ -class Time -{ -public: - - C4_ALWAYS_INLINE Time() : m_microsecs(0) {} - C4_ALWAYS_INLINE Time(time_type microsecs) : m_microsecs(microsecs) {} - - C4_ALWAYS_INLINE operator time_type () const { return m_microsecs; } - C4_ALWAYS_INLINE void operator= (time_type t) { m_microsecs = t; } - - C4_ALWAYS_INLINE void m(time_type minutes) { m_microsecs = minutes * 60.e6; } - C4_ALWAYS_INLINE time_type m() const { return m_microsecs / 60.e6; } - - C4_ALWAYS_INLINE void s(time_type seconds) { m_microsecs = seconds * 1.e6; } - C4_ALWAYS_INLINE time_type s() const { return m_microsecs * 1.e-6; } - - C4_ALWAYS_INLINE void ms(time_type miliseconds) { m_microsecs = miliseconds * 1.e3; } - C4_ALWAYS_INLINE time_type ms() const { return m_microsecs * 1.e-3; } - - C4_ALWAYS_INLINE void us(time_type microseconds) { m_microsecs = microseconds; } - C4_ALWAYS_INLINE time_type us() const { return m_microsecs; } - - C4_ALWAYS_INLINE void ns(time_type nanoseconds) { m_microsecs = nanoseconds * 1.e-3; } - C4_ALWAYS_INLINE time_type ns() const { return m_microsecs * 1.e3; } - -public: - - C4_ALWAYS_INLINE static Time currtime() { return Time(c4::currtime()); } - C4_ALWAYS_INLINE static Time exetime() { return Time(c4::exetime()); } - -private: - - time_type m_microsecs; - -}; - -C4_ALWAYS_INLINE Time nsecs(time_type val) { return Time(val * time_type(1.e-3)); } -C4_ALWAYS_INLINE Time usecs(time_type val) { return Time(val); } -C4_ALWAYS_INLINE Time msecs(time_type val) { return Time(val * time_type(1.e3)); } -C4_ALWAYS_INLINE Time secs(time_type val) { return Time(val * time_type(1.e6)); } -C4_ALWAYS_INLINE Time mins(time_type val) { return Time(val * time_type(60.e6)); } -C4_ALWAYS_INLINE Time hours(time_type val) { return Time(val * time_type(3600.e6)); } - -} // namespace c4 - -#ifdef __clang__ -# pragma clang diagnostic pop -#elif defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - -#endif /* _C4_TIME_HPP_ */