2021-05-18 23:03:42 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "logger.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
using namespace std::chrono;
|
|
|
|
class benchmark
|
|
|
|
{
|
|
|
|
public:
|
2023-03-01 21:27:15 +00:00
|
|
|
explicit benchmark(std::string name = "") :
|
|
|
|
m_start(high_resolution_clock::now()),
|
|
|
|
m_name(name)
|
|
|
|
{
|
|
|
|
}
|
2021-05-18 23:03:42 +02:00
|
|
|
|
|
|
|
void get_runtime()
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
auto now = high_resolution_clock::now();
|
2021-05-18 23:03:42 +02:00
|
|
|
auto milliseconds_elapsed = duration_cast<milliseconds>(now - m_start);
|
|
|
|
auto microseconds_elapsed = duration_cast<microseconds>(now - m_start);
|
2023-03-01 21:27:15 +00:00
|
|
|
LOG(INFO) << m_name << " finished with a resulting time of: " << milliseconds_elapsed.count() << "ms "
|
|
|
|
<< microseconds_elapsed.count() % 1000 << "us";
|
2021-05-18 23:03:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_start = high_resolution_clock::now();
|
|
|
|
}
|
2023-03-01 21:27:15 +00:00
|
|
|
|
2021-05-18 23:03:42 +02:00
|
|
|
private:
|
|
|
|
high_resolution_clock::time_point m_start;
|
|
|
|
std::string m_name;
|
|
|
|
};
|
|
|
|
}
|