Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SendMessage / PostMessage speed test
UINT __cdecl TestThread(LPVOID pData)
{
CMessageSpeedTestDlg* p = static_cast<CMessageSpeedTestDlg*>(pData);
QueryPerformanceCounter(&p->m_Begin);
p->SendMessage(WM_USER_COMPLETE);
return 0;
}
void CMessageSpeedTestDlg::OnBnClickedButtonStart()
{
QueryPerformanceFrequency(&m_Freq);
m_Count = 0;
m_Sum = 0;
CString buffer;
m_CtrlEditTarget.GetWindowText(buffer);
m_Target = _ttoi(buffer);
AfxBeginThread(TestThread, this);
}
LRESULT CMessageSpeedTestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
float time;
CString buff;
switch (message) {
case WM_USER_COMPLETE:
QueryPerformanceCounter(&m_End);
m_Sum += m_End.QuadPart - m_Begin.QuadPart;
time = static_cast<float>(m_Sum) / m_Freq.QuadPart;
buff.Format(_T("%d"), m_Count);
m_CtrlEditCount.SetWindowText(buff);
buff.Format(_T("%f"), time);
m_CtrlEditTime.SetWindowText(buff);
buff.Format(_T("%f"), time * 1000000 / m_Count);
m_CtrlEditAverage.SetWindowText(buff);
if (m_Count < m_Target) {
m_Count++;
AfxBeginThread(TestThread, this);
}
break;
default:
break;
}
return CDialogEx::WindowProc(message, wParam, lParam);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.