45 lines
864 B
C++
45 lines
864 B
C++
|
/*
|
||
|
* IXBench.cpp
|
||
|
* Author: Benjamin Sergeant
|
||
|
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
|
||
|
*/
|
||
|
|
||
|
#include "IXBench.h"
|
||
|
|
||
|
#include <spdlog/spdlog.h>
|
||
|
|
||
|
namespace ix
|
||
|
{
|
||
|
Bench::Bench(const std::string& description)
|
||
|
: _description(description)
|
||
|
, _start(std::chrono::system_clock::now())
|
||
|
, _reported(false)
|
||
|
{
|
||
|
;
|
||
|
}
|
||
|
|
||
|
Bench::~Bench()
|
||
|
{
|
||
|
if (!_reported)
|
||
|
{
|
||
|
report();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Bench::report()
|
||
|
{
|
||
|
auto now = std::chrono::system_clock::now();
|
||
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start);
|
||
|
|
||
|
_ms = milliseconds.count();
|
||
|
spdlog::info("{} completed in {} ms", _description, _ms);
|
||
|
|
||
|
_reported = true;
|
||
|
}
|
||
|
|
||
|
uint64_t Bench::getDuration() const
|
||
|
{
|
||
|
return _ms;
|
||
|
}
|
||
|
}
|