You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
598 B
C++
26 lines
598 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <chrono>
|
|
|
|
class MyTimer {
|
|
public:
|
|
explicit MyTimer(const std::string &name) {
|
|
_name = name;
|
|
_start = std::chrono::steady_clock::now();
|
|
}
|
|
|
|
~MyTimer() {
|
|
_end = std::chrono::steady_clock::now();
|
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(_end - _start).count();
|
|
std::printf("%s cast %dms\n", _name.c_str(), duration);
|
|
}
|
|
|
|
private:
|
|
std::chrono::time_point<std::chrono::steady_clock> _start;
|
|
std::chrono::time_point<std::chrono::steady_clock> _end;
|
|
std::string _name;
|
|
};
|
|
|
|
#define TIMER() MyTimer __timer(__FUNCTION__);
|