class TimeCasterMicro final
{
public:
TimeCasterMicro()
:record{std::chrono::system_clock::now()}
{
std::cout << "Start!\n";
}
~TimeCasterMicro()
{
auto now = std::chrono::system_clock::now();
auto time_span = std::chrono::duration_cast<std::chrono::microseconds>(now - record);
std::cout << "Spend Time = "
<< time_span.count()
<< "us"
<< std::endl;
}
public:
std::chrono::system_clock::time_point record;
};
// 使用:
auto time = new TimeCasterMicro;
delete time;
{
TimeCasterMicro time;
}
{
std::unique_ptr<TimeCasterMicro> time(new TimeCasterMicro);
}