编程语言
首页 > 编程语言> > c++11 耗时计算 微秒级

c++11 耗时计算 微秒级

作者:互联网

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);
}

标签:11,std,chrono,auto,c++,time,微秒,now,TimeCasterMicro
来源: https://blog.csdn.net/qq_41540355/article/details/120778218