首页 > 编程语言 > 详细

C++ 自动计时

时间:2021-06-16 22:16:07      阅读:32      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<chrono>

struct Timer
{
	std::chrono::time_point<std::chrono::steady_clock>start, end;
	std::chrono::duration<float>duration;

	Timer()
	{
		start = std::chrono::high_resolution_clock::now();
	}

	~Timer()
	{
		end = std::chrono::high_resolution_clock::now();
		duration = end - start;

		float ms = duration.count() * 1000.0f;
		std::cout << "Timer took " << ms << " ms" << std::endl;
	}
};

void Function()
{
	Timer timer;
	for (int i = 0; i < 100; i++)
	{
		std::cout << "hello " << std::endl;
	}
}

int main()
{
	Function();

	std::cin.get();
}

C++ 自动计时

原文:https://www.cnblogs.com/chengmf/p/14890935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!