您当前的位置: 首页 >  c++

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

c++11测试时间封装

qianbo_insist 发布时间:2021-06-27 12:14:41 ,浏览量:0

1、定义一个测试时间函数

类似于windows下Get Tick Count() 这种函数,时间是不准的 使用std::chrono::system_clock来获取时间

class TicToc
{
public:
	TicToc()
	{
		tic();
	}

	void tic()
	{
		start = std::chrono::system_clock::now();
	}

	double toc()
	{
		end = std::chrono::system_clock::now();
		std::chrono::duration elapsed_seconds = end - start;
		return elapsed_seconds.count() * 1000;
	}

private:
	std::chrono::time_point start, end;
};

输出为毫秒

2、定义测试函数
int result_future()
{
	int i=0,ret = 0;
	std::this_thread::sleep_for(std::chrono::seconds(2));
	return ret + 1;
}

int result_add(int x, int y)
{
	return x + y;
}


void print_point(int x)
{
	std::cout             
关注
打赏
1663161521
查看更多评论
0.0391s