C/C++教程

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);
}
这篇关于c++11 耗时计算 微秒级的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!