Esempio n. 1
0
void BaseApp::Run()
{
	CStopwatch timer;
	int sum = 0;
	int counter = 0;

	int deltaTime = 0;
	while (1)
	{
		timer.Start();
		if (kbhit())
		{
			KeyPressed (getch());
			if (!FlushConsoleInputBuffer(mConsoleIn))
				cout<<"FlushConsoleInputBuffer failed with error "<<GetLastError();
		}

		UpdateF((float)deltaTime / 1000.0f);
		Render();
		Sleep(1);

		while (1)
		{
			deltaTime = timer.Now();
			if (deltaTime > 20)
				break;
		}

		sum += deltaTime;
		counter++;
		if (sum >= 1000)
		{
			TCHAR  szbuff[255];
			StringCchPrintf(szbuff, 255, TEXT("FPS: %d"), counter);
			SetConsoleTitle(szbuff);

			counter = 0;
			sum = 0;
		}
	}
}
Esempio n. 2
0
void MeasureConcurrentOperation(
   TCHAR* operationName, DWORD nThreads, OPERATIONFUNC operationFunc) {
   HANDLE* phThreads = new HANDLE[nThreads];

   SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
   for (DWORD currentThread = 0; currentThread < nThreads; currentThread++) {
      phThreads[currentThread] = 
         CreateThread(NULL, 0, ThreadIterationFunction, operationFunc, 0, NULL);
   }
   SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);

   CStopwatch watch;
   WaitForMultipleObjects(nThreads, phThreads, TRUE, INFINITE);
   __int64 elapsedTime = watch.Now();
   _tprintf(
	   TEXT("Threads=%u, Milliseconds=%u, Test=%s\n"), 
      nThreads, (DWORD)elapsedTime, operationName);

   // Don't forget to clean up the thread handles
   for (DWORD currentThread = 0; currentThread < nThreads; currentThread++) {
      CloseHandle(phThreads[currentThread]);
   }
   delete phThreads;
}