mirror of
https://github.com/Icinga/icinga2.git
synced 2025-08-21 09:38:16 +02:00
38 lines
633 B
C++
38 lines
633 B
C++
/* Icinga 2 | (c) 2024 Icinga GmbH | GPLv2+ */
|
|
|
|
#pragma once
|
|
|
|
#include "base/atomic.hpp"
|
|
#include <chrono>
|
|
|
|
namespace icinga
|
|
{
|
|
|
|
/**
|
|
* Benchmark result.
|
|
*
|
|
* @ingroup base
|
|
*/
|
|
class Benchmark
|
|
{
|
|
public:
|
|
using Clock = std::chrono::steady_clock;
|
|
|
|
Benchmark& operator+=(const Clock::duration&) noexcept;
|
|
Benchmark& operator+=(const Clock::time_point&) noexcept;
|
|
|
|
/**
|
|
* @return The total accumulated time in seconds
|
|
*/
|
|
template<class T>
|
|
operator T() const noexcept
|
|
{
|
|
return std::chrono::duration<T>(Clock::duration(m_Sum.load(std::memory_order_relaxed))).count();
|
|
}
|
|
|
|
private:
|
|
Atomic<Clock::duration::rep> m_Sum {0};
|
|
};
|
|
|
|
}
|