2020-03-25 04:29:09 +01:00
|
|
|
/*
|
|
|
|
* IXBench.cpp
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXBench.h"
|
|
|
|
|
2020-03-25 04:53:25 +01:00
|
|
|
#include <iostream>
|
2020-03-25 04:29:09 +01:00
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
Bench::Bench(const std::string& description)
|
|
|
|
: _description(description)
|
2020-03-25 04:53:25 +01:00
|
|
|
, _start(std::chrono::high_resolution_clock::now())
|
2020-03-25 04:29:09 +01:00
|
|
|
, _reported(false)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bench::~Bench()
|
|
|
|
{
|
|
|
|
if (!_reported)
|
|
|
|
{
|
|
|
|
report();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bench::report()
|
|
|
|
{
|
2020-03-25 04:53:25 +01:00
|
|
|
auto now = std::chrono::high_resolution_clock::now();
|
2020-03-25 04:29:09 +01:00
|
|
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start);
|
|
|
|
|
|
|
|
_ms = milliseconds.count();
|
2020-03-25 04:53:25 +01:00
|
|
|
std::cerr << _description << " completed in " << _ms << "ms" << std::endl;
|
2020-03-25 04:29:09 +01:00
|
|
|
|
|
|
|
_reported = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Bench::getDuration() const
|
|
|
|
{
|
|
|
|
return _ms;
|
|
|
|
}
|
2020-03-25 04:37:55 +01:00
|
|
|
} // namespace ix
|