Sample Code: Measure FPS in HPS MFC Sandbox

Language: C++

Out-of-the-box, the HPS MFC Sandbox does not have a method to do a general FPS performance test. To address that, code is provided below that can be inserted in one of the user code slots:

  1. Open the Visual Studio solution “visualize_v140.sln” found in the directory:
    HOOPS_Visualize_202X_SPX\samples
  2. In the VS project “hps_mfc_sandbox_v14x”, add the following code to the file “CHPSView.cpp” as one of the user code slots:
void CHPSView::OnUserCode3()
{
	double t0, t1;
	int animation_steps = 30;
	int total_animation_steps = 0;
	int minimum_time = 3000;

	t0 = HPS::Database::GetTime();
	do
	{
		for (int i = 0; i < animation_steps; ++i)
		{
			_canvas.GetFrontView().GetSegmentKey().GetCameraControl().Orbit((float)(360 / animation_steps), 0);
			_canvas.UpdateWithNotifier().Wait();
		}
		total_animation_steps += animation_steps;
		t1 = HPS::Database::GetTime();
	} while (t1 - t0 < minimum_time);

	double time_passed = t1 - t0;
	double myFPS = total_animation_steps * 1000 / (t1 - t0);

	CString strMsg;
	strMsg.Format(_T("FPS: %f"), myFPS);
	AfxMessageBox(strMsg);
}

The variable minimum_time can be adjusted to run a longer or shorter test.

Attached is a screenshot of the result: