celapsed.h

来自「毫秒级的高精度计数器」· C头文件 代码 · 共 32 行

H
32
字号
#include "Winbase.h"
class celapsed
{
public :
	celapsed(){
		// get the frequency of the counter
		initialized = QueryPerformanceFrequency( (LARGE_INTEGER *)&frequency );
	};
	bool begin(){
		if( ! initialized )
			return 0; // error - couldn't get frequency
		// get the starting counter value
		return QueryPerformanceCounter( (LARGE_INTEGER *)&begintime );
	}; // start timing
	double end(){
		if( ! initialized )
			return 0.0; // error - couldn't get frequency
		// get the ending counter value
		__int64 endtime;
		QueryPerformanceCounter( (LARGE_INTEGER *)&endtime );
		// determine the elapsed counts
		__int64 elapsed = endtime - begintime;
		// convert counts to time in seconds and return it
		return (double)elapsed / (double)frequency;
	}; // stop timing and get elapsed time in seconds

private :
	int initialized;
	__int64 frequency;
	__int64 begintime;
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?