add timer
This commit is contained in:
29
include/llmr/util/timer.hpp
Normal file
29
include/llmr/util/timer.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef LLMR_UTIL_TIMER
|
||||
#define LLMR_UTIL_TIMER
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
namespace llmr {
|
||||
namespace util {
|
||||
|
||||
class timer {
|
||||
using hr = std::chrono::high_resolution_clock;
|
||||
public:
|
||||
timer(const std::string &name) : name(name), start(hr::now()) {}
|
||||
~timer() {
|
||||
using namespace std::chrono;
|
||||
std::cerr << name << ": "
|
||||
<< (double)duration_cast<microseconds>(hr::now() - start).count() / 1000
|
||||
<< "ms" << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string name;
|
||||
const hr::time_point start;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user