Updated to initial implementation using cpp.

This commit is contained in:
2026-08-07 13:32:49 +02:00
parent 2eb04509db
commit 78a1607789
32 changed files with 325 additions and 177 deletions

29
Timer.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include <chrono>
#include <atomic>
namespace tools
{
template <typename Clock = std::chrono::high_resolution_clock>
class stopwatch
{
const typename Clock::time_point start_point;
public:
stopwatch() :
start_point(Clock::now())
{}
template <typename Rep = typename Clock::duration::rep, typename Units = typename Clock::duration>
Rep elapsed_time() const
{
std::atomic_thread_fence(std::memory_order_relaxed);
auto counted_time = std::chrono::duration_cast<Units>(Clock::now() - start_point).count();
std::atomic_thread_fence(std::memory_order_relaxed);
return static_cast<Rep>(counted_time);
}
};
using precise_stopwatch = stopwatch<>;
using system_stopwatch = stopwatch<std::chrono::system_clock>;
using monotonic_stopwatch = stopwatch<std::chrono::steady_clock>;
}