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
|
|
|
|
{
|
2023-03-21 10:05:45 +00:00
|
|
|
#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
|
|
|
|
2023-03-21 10:05:45 +00:00
|
|
|
struct DebugBenchmark
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-03-21 10:05:45 +00:00
|
|
|
inline DebugBenchmark(AuString &&message) : message_(AuMove(message))
|
|
|
|
{
|
|
|
|
this->stopwatch_.Start();
|
|
|
|
}
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2023-03-21 10:05:45 +00:00
|
|
|
inline ~DebugBenchmark()
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
|
2023-03-21 10:05:45 +00:00
|
|
|
inline void Finish()
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
2023-03-21 10:05:45 +00:00
|
|
|
auto uEndNS = this->stopwatch_.EndNS();
|
|
|
|
Aurora::Logging::LogDbg("[Benchmark] {} took {}", message_, ConvertNSToTimescale(uEndNS));
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-07-08 16:28:24 +00:00
|
|
|
Stopwatch<ClockSteady> stopwatch_;
|
2021-06-27 21:25:29 +00:00
|
|
|
AuString message_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2023-03-21 10:05:45 +00:00
|
|
|
struct DebugBenchmark
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
template<typename ... T>
|
|
|
|
DebugBenchmark(T... args) {}
|
|
|
|
|
2023-03-21 10:05:45 +00:00
|
|
|
inline void Finish() {}
|
2021-06-27 21:25:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SysBenchmark(...) Aurora::Time::DebugBenchmark _(__VA_ARGS__);
|