C++11计算FPS函数示例

添加以下头文件和命名空间

#include <chrono>
using namespace std;
using namespace std::chrono;

函数如下:

double fps()
{
	static double fps = 0.0;
	static int frameCount = 0;
	static auto lastTime = system_clock::now();
	static auto curTime = system_clock::now();
	
	curTime = system_clock::now();
	
	auto duration = duration_cast<microseconds>(curTime - lastTime);
	double duration_s = double(duration.count()) * microseconds::period::num / microseconds::period::den;

	if (duration_s > 2)//2秒之后开始统计FPS
	{
		fps = frameCount / duration_s;
		frameCount = 0;
		lastTime = curTime;
	}

	++frameCount;

	return fps;
}

本文参看了博文https://blog.csdn.net/u013390476/article/details/50209603

上一篇:Find Backpacker Jobs in Australia


下一篇:php – Laravel – 调度不在存储库中工作的作业