AuroraRuntime/Include/Aurora/Time/DebugBenchmark.hpp

53 lines
1.1 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: DebugBenchmark.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
#include <Aurora/Console/Console.hpp>
namespace Aurora::Time
{
#if ((defined(AU_FORCE_BENCHMARK) || defined(AU_CFG_ID_DEBUG) || defined(AU_CFG_ID_INTERNAL)) && (!defined(AU_FORCE_NOBENCHMARK)))
2021-06-27 21:25:29 +00:00
struct DebugBenchmark
2021-06-27 21:25:29 +00:00
{
inline DebugBenchmark(AuString &&message) : message_(AuMove(message))
{
this->stopwatch_.Start();
}
2021-06-27 21:25:29 +00:00
inline ~DebugBenchmark()
2021-06-27 21:25:29 +00:00
{
Finish();
}
inline void Finish()
2021-06-27 21:25:29 +00:00
{
auto uEndNS = this->stopwatch_.EndNS();
Aurora::Logging::LogDbg("[Benchmark] {} took {}", message_, ConvertNSToTimescale(uEndNS));
2021-06-27 21:25:29 +00:00
}
private:
Stopwatch<ClockSteady> stopwatch_;
2021-06-27 21:25:29 +00:00
AuString message_;
};
#else
struct DebugBenchmark
2021-06-27 21:25:29 +00:00
{
template<typename ... T>
DebugBenchmark(T... args) {}
inline void Finish() {}
2021-06-27 21:25:29 +00:00
};
#endif
}
#define SysBenchmark(...) Aurora::Time::DebugBenchmark _(__VA_ARGS__);