티스토리 뷰

C & C++/MS VC++

Time Measurer with <windows.h>

DWGoon 2009. 11. 28. 16:27
#ifndef DW_TIMEMSR__H__
#define DW_TIMEMSR__H__

#include 

namespace DW {

	class TimeMsr {
	public:
		// LARGE_INTEGER.QuadPart is LONGLONG(a.k.a __int64)
		 LARGE_INTEGER larBegin;
		 LARGE_INTEGER larEnd;
		 static LARGE_INTEGER larFrequency;

	public:
		
		TimeMsr() {
			if (larFrequency.QuadPart == 0) // if the value of frequency is not loaded
			   QueryPerformanceFrequency(&larFrequency);
			   // retrieves the frequency of the high-resolution performance counter
		}

		inline void begin() {
			QueryPerformanceCounter(&larBegin);
		}

		inline void end() {
			QueryPerformanceCounter(&larEnd);
		}

		inline double getTimeElapsed() {
			// The unit is second(NOT milli-second).
			return (double)(larEnd.QuadPart - larBegin.QuadPart)
				/ (double)larFrequency.QuadPart;
		}

	}; // end of class TimeMsr

	LARGE_INTEGER TimeMsr::larFrequency = {0}; // 


} // end of namespace DW


// reference : http://i0nucleus.egloos.com/2240494

#endif // DW_TIMEMSR__H__

'C & C++ > MS VC++' 카테고리의 다른 글

MSVC++로 Dll 파일 제작 - 소스코드 기본틀  (0) 2009.11.05
댓글