47using Clock = std::chrono::steady_clock;
85template <
typename Duration>
87 return std::chrono::duration_cast<Duration>(Clock::now() - std::chrono::time_point<Clock, Duration>());
97template <
typename Duration>
99 return now<Duration>() - start;
109constexpr const char* time_unit(MilliSec) {
return "ms"; }
110constexpr const char*
time_unit(MicroSec) {
return "mu"; }
134template <
typename Duration = MilliSec>
153 src_ = now<Duration>();
162 return now<Duration>() - src_;
172#if !(defined(__TEC_WINDOWS__) || defined(__TEC_MINGW__))
177#if defined(__TEC_APPLE__)
178#include <sys/syslimits.h>
180#include <linux/limits.h>
190 if (gethostname(host,
sizeof(host)) == 0)
202 uid_t uid = geteuid();
203 struct passwd* pw = getpwuid(uid);
216#if defined(__TEC_WINDOWS__) || defined(__TEC_MINGW__)
218#include "tec/mswin/tec_win_utils.hpp"
A simple timer for measuring elapsed time.
Definition tec_utils.hpp:135
Duration stop()
Stops the timer and returns the elapsed time.
Definition tec_utils.hpp:161
Timer()
Constructs and starts a timer.
Definition tec_utils.hpp:144
void start()
Starts or restarts the timer.
Definition tec_utils.hpp:152
Common definitions and utilities for the tec namespace.
std::string getusername()
Retrieves the logged-in username.
Definition tec_utils.hpp:201
constexpr Seconds one_day()
Returns a constant duration of one day.
Definition tec_utils.hpp:124
constexpr const char * time_unit(Seconds)
Returns the unit string for a duration type.
Definition tec_utils.hpp:108
std::chrono::steady_clock Clock
Type alias for a monotonic clock suitable for measuring intervals.
Definition tec_utils.hpp:47
std::chrono::time_point< Clock, MilliSec > TimePointMs
Type alias for a time point in milliseconds.
Definition tec_utils.hpp:67
std::chrono::seconds Seconds
Type alias for seconds duration.
Definition tec_utils.hpp:52
std::chrono::time_point< Clock, Seconds > TimePointSec
Type alias for a time point in seconds.
Definition tec_utils.hpp:57
Duration now()
Returns the current time as a duration since the epoch.
Definition tec_utils.hpp:86
Duration since(Duration start)
Returns the duration since a specified start time.
Definition tec_utils.hpp:98
std::chrono::milliseconds MilliSec
Type alias for milliseconds duration.
Definition tec_utils.hpp:62
constexpr Seconds one_hour()
Returns a constant duration of one hour.
Definition tec_utils.hpp:117
std::string getcomputername()
Retrieves the computer hostname.
Definition tec_utils.hpp:188
std::chrono::microseconds MicroSec
Type alias for microseconds duration.
Definition tec_utils.hpp:72
std::chrono::time_point< Clock, MicroSec > TimePointMu
Type alias for a time point in microseconds.
Definition tec_utils.hpp:77