1. Jason McKesson
  2. GL Profile Suite

Source

GL Profile Suite / tests / util / CPUTiming.cpp


#include <algorithm>
#include <iterator>
#include <vector>
#include "CPUTiming.h"

#ifdef WIN32
#include <windows.h>		// Header File For Windows
#endif //WIN32


namespace util
{
#ifdef WIN32
	double GetPrecisionCPUTimeInSeconds()
	{
		LARGE_INTEGER frequency;
		LARGE_INTEGER currTime;

		QueryPerformanceFrequency(&frequency);
		QueryPerformanceCounter(&currTime);

		return (double)currTime.QuadPart / (double)frequency.QuadPart;
	}
#endif //WIN32

	const int TOUCH_MEMORY_SIZE = 1024 * 1024;

	void EmptyDataCache()
	{
		//Touch a *lot* of memory.
		std::vector<char> theVec;
		theVec.reserve(TOUCH_MEMORY_SIZE);
		std::fill_n(std::back_inserter(theVec), TOUCH_MEMORY_SIZE, 1); //Make sure it's touched; no memcpy .
	}
}