File timespent.h
File List > code_source > templat > include > TempLat > util > log > timespent.h
Go to the documentation of this file
#ifndef TEMPLAT_UTIL_LOG_TIMESPENT_H
#define TEMPLAT_UTIL_LOG_TIMESPENT_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Wessel Valkenburg, Year: 2019
#include <chrono>
#include <iostream>
#include "TempLat/util/tdd/tddmacros.h"
namespace TempLat
{
class TimeSpent
{
public:
// Put public methods here. These should change very little over time.
TimeSpent() : mStart(now()) {}
static auto getProcessAge() { return (now() - getProcessStart()).count(); }
auto get() const { return (now() - mStart).count(); }
friend std::ostream &operator<<(std::ostream &ostream, const TimeSpent &ts)
{
ostream << ts.get() << "ms";
return ostream;
}
private:
/* Put all member variables and private methods here. These may change arbitrarily. */
std::chrono::milliseconds mStart;
static std::chrono::milliseconds now()
{
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
}
inline static std::chrono::milliseconds getProcessStart()
{
static std::chrono::milliseconds pStart = now();
return pStart;
};
public:
template <typename TestObjectUnknownHere> static inline void Test(TestObjectUnknownHere &tdd);
};
} // namespace TempLat
#endif